Analysis of dependent double for

Here is the algorithm:

int sum = 0 for (int i = 2N; i > 0; i = i / 4) {   for (int j = 0; j < i; j+=2) {     sum++   } } 

I figured this would be linearithmic, but it’s just linear. I would appreciate seeing a formalized summation and not a qualitative explanation. I have tried doing this but I fail to get linear runtime.

Optimal strategy for tossing three dependent coins

Suppose that I have three correlated coins. The marginal probability of Head of coin $ i$ is denoted by $ p_i$ .

The conditional probability of head for coin $ i$ given the outcomes of coin $ j$ and $ k$ is denoted by $ p_i|x_j,x_k$ , where $ x_j,x_k\in\{H,T\}$ . We can similarly construct the conditional probability of $ i$ given $ x_j$ .

Each coin can be tossed at most once and you receive a $ 1 for a head and -$ 1 for a tail. You don’t have to toss all the coins, and your objective is to maximize the total reward.

What would be the optimal sequence of tossing coins in this case?

If the coins are independent of each other, the order wouldn’t matter. The optimal strategy should be “flip coin i if $ p_i>\frac{1}{2}$ “. For the case of two coins, it can be shown that it is always the best to flip the coin with a higher marginal $ p_i$ . However, this doesn’t have to be optimal for three coin cases. I’ve been thinking about this problem for a quite long time but can’t come up with a general solution or an intuition that might help..

Is the additional effect of Radiance of the Dawn dependent on the first effect?

The Light Domain Cleric Channel Divinity: Radiance of the Dawn has two effects:

As an action, you present your holy symbol, and any magical darkness within 30 feet of you is dispelled. Additionally, each hostile creature within 30 feet of you must make a Constitution saving throw.

Is the additional effect dependent upon the first effect? i.e. does the Channel Divinity require the presence of magical darkness within range before it can be used?

Solving time dependent boundary conditions heat PDE

I am attempting to solve the heat equation $ \frac{\partial T}{\partial t}=\nabla^2T$ , where $ T=T(x,y,z,t)$ , subject to the following boundary conditions:

$ \frac{\partial T}{\partial x}|_{x=10}=\frac{\partial T}{\partial x}|_{x=-10}=0$

$ \frac{\partial T}{\partial y}|_{y=10}=0$

$ T(0,0,z_{crit}(t),t)=f(t)$ where $ z_{crit}(t)=t$ and $ f(t)=e^{-t}$

$ \frac{\partial T}{\partial y}|_{y=0}=\frac{\partial T}{\partial z}|_{z=0}=0$

But my attempted code has not worked properly and I encounter frequently many different errors.

Is there any way to fix this issue?

Thanks in advance.

Interaction for dependent sibling input fields?

I have two fields in a form – Country and Organisation. These hold the same hierarchy and are dependent on each other.
Meaning, the user should be able to either select a country first and then select an Organisation that falls under the Country or, select an Organisation first and then select the Countries that the Organisation exists in.

So something like the following:
(If user chooses Organisation tab first, hovering on Uniqlo only displays the countries it is present in. If he chooses the country tab first, hovering over US will only display Organisations that are present in the US)

enter image description here

I’m convinced that this is not an ideal design and could be very confusing for some but I also can’t think of another alternative. Asking the user to choose “What would you like to choose first? Org or the Country?” seems like one way to go but still seems like bad design. Is there some clever design pattern for such cases? To throw in some context, this is for a web only admin access control UI.

conditional probability of dependent random variables

Suppose I have 3 random variables:

$ $ X \sim \mbox{Bernoulli}(1/2)$ $ $ $ Z \sim \mbox{Normal}(0,1)$ $ $ $ Y = X+Z$ $

How do I compute the conditional probability:

$ $ P(X=1 | Y=y)$ $


Probability[ X == 1 \[Conditioned] X + Z == y,             {             X \[Distributed] BernoulliDistribution[1/2]            ,Z \[Distributed] NormalDistribution[]            }          ] 


D[Probability[ X == 1 \[Conditioned] X + Z >= y,             {             X \[Distributed] BernoulliDistribution[1/2]            ,Z \[Distributed] NormalDistribution[]            }          ],y] 


Likelihood[       TransformedDistribution[X + Z,                     {                     X \[Distributed]BernoulliDistribution[1/2],                     Z \[Distributed] NormalDistribution[]}]            , {y}] 

Pencil and Paper attempt:

$ $ P(X=1 | Y=y) = \frac{P(X=1 , Y=y)}{P(Y=y)}$ $ $ $ = \frac{P(X=1 , X+Z=y)}{P(Y=y)}$ $ $ $ = \frac{P(X=1)P(Z=y-1)}{P(Y=y)}$ $ $ $ = \frac{P(X=1)P(Z=y-1)}{P(X=1)P(Z=y-1)+P(X=0)P(Z=y-0)}$ $

$ $ P(Z=y)=\frac{e^{-\frac{y^2}{2}}}{\sqrt{2 \pi }}$ $ $ $ P(Z=y-0)=\frac{e^{-\frac{y^2}{2}}}{\sqrt{2 \pi }}$ $ $ $ P(Z=y-1)=\frac{e^{-\frac{1}{2} (y-1)^2}}{\sqrt{2 \pi }}$ $ $ $ P(X=1)=\frac{1}{2}$ $ $ $ P(X=0)=\frac{1}{2}$ $

$ $ P(X=1 | Y=y) = \frac{e^{-\frac{1}{2} (y-1)^2}}{2 \sqrt{2 \pi } \left(\frac{e^{-\frac{y^2}{2}}}{2 \sqrt{2 \pi }}+\frac{e^{-\frac{1}{2} (y-1)^2}}{2 \sqrt{2 \pi }}\right)}$ $

$ $ P(X=1|Y=y) = \frac{e^y}{e^y+\sqrt{e}}$ $

How to get super attribute dependent relation on custom page

I need to get list of all super attribute on my custom phtml page.

Like I have 3 attributes Color, Size, Height.

So I need three drop-down on my custom page where after selecting color, dependent size value should be populate in size drop-down and after selecting size, dependent height attribute value should be populated in height drop-down.

I tried with $ product->getTypeInstance(true)->getConfigurableAttributesAsArray($ product)

It gives attributes used for particular product but I am not able to make it dependent does any one has solution for this.

Dependent dropdowns in Magento 2 Frontend

How can I create a pair of dropdowns such that when one is selected, the options for the other one are updated?


<?php $  stateList = $  block->getStates(); ?>      <div>         <h3 class="text-uppercase margin-bottom15"><?php echo __('Pedir una Cita') ?></h3>         <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p>         <div>             <form id="search_cita">                 <div class="form-group states required">                     <select id="state" name="state">                         <option value="">Estado</option>                         <?php foreach($  stateList as $  index): ?>                         <?php  echo '<option value="'.$  index['state'].'">'.$  index['state'].'</option>'; ?>                         <?php endforeach ?>                     </select>                 </div>                 <div class="form-group cities required">                     <div class="control">                         <select name="city" id="city" class="input-text" data-validate="{required:true}">                             <!--option value="">Ciudad</option-->                             </select>                     </div>                 </div>                  <div>                     <button type="submit" class="btn btn-primary"><?php echo __('Buscar un taller') ?></button>                 </div>              </form>         </div>     </div>      <script>         require(['jquery', 'jquery/ui'],function(){                 jQuery(document).on('change','#state',function() {                     var param = 'frame='+jQuery('#state option:selected').attr('value');                     var url = "<?php echo $  block->getStateAction(); ?>";                     //alert(param);                     jQuery.ajax({                         showLoader: true,                         url: url,                         data: param,                         type: "POST",                         dataType: 'json'                     }).done(function (data) {                         jQuery('#city').empty();                         jQuery('#city').append(data);                     });                  });         });     </script> 


<?php namespace Morwi\Citas\Block;  class Display extends \Magento\Framework\View\Element\Template {     protected $  _isScopePrivate;     public function __construct(         \Magento\Framework\View\Element\Template\Context $  context,         \Magento\Directory\Block\Data $  directoryBlock,         array $  data = []     ) {         parent::__construct($  context, $  data);         $  this->directoryBlock = $  directoryBlock;         $  this->_isScopePrivate = true;     }      public function getStateAction() {         return $  this->getUrl('citas/index/display', ['_secure' => true]);      } } 


<?php namespace Morwi\Citas\Controller\Index;  use Magento\Framework\Controller\ResultFactory;   class Display extends \Magento\Framework\App\Action\Action {     protected $  _resultPageFactory;     public function __construct(         \Magento\Framework\App\Action\Context $  context,         \Magento\Framework\View\Result\PageFactory $  resultPageFactory     ){                   parent::__construct($  context);         $  this->_resultPageFactory = $  resultPageFactory;     }      public function execute() {         //*         $  result = $  this->resultFactory->create(ResultFactory::TYPE_JSON);          $  objectManager = \Magento\Framework\App\ObjectManager::getInstance();         $  resource = $  objectManager->get('Magento\Framework\App\ResourceConnection');         $  connection = $  resource->getConnection();          $  html='<option selected="selected" value="">Ciudad</option>';          $  stateName = $  this->getRequest()->getParam('frame');          if($  stateName!='') {              $  tblSL = $  resource->getTableName('store_locator');              $  sql = "SELECT DISTINCT city from " . $  tblSL . " WHERE state LIKE '%". $  stateName ."%'";             $  city = $  connection->fetchAll($  sql);                foreach($  city as $  index){                 $  hmtl= '<option value="'.$  index['city'].'">'.$  index['city'].'</option>';              }         }          return $  result->setData(['success'=>true,'value'=>$  html]);         //*/        }  }  ?> 

But this returns to me

enter image description here

in success I don’t paint the html

Any help would be appreciated.


Magento 2 : Dependent dropdowns in knockout

I am trying to override Magento/Checkout/view/frontend/web/js/view/shipping-address/list.js and Magento/Checkout/view/frontend/web/template/shipping-address/list.html.

I need to create two dropdowns here such that when one is selected, the other one gets it’s values. Like countries and provinces.

The array of values for each dropdown is created in php in config provider.

How can I create these dropdowns in knockout js? Thanks!