Calculates the probabilities of the chosen alternative, and the long
        format probabilities for this model and dataset.
778281
def convenience_calc_probs(self, params):
        
        orig_nest_coefs, betas = self.convenience_split_params(params)
        natural_nest_coefs = nc.naturalize_nest_coefs(orig_nest_coefs)

        args = [natural_nest_coefs,
                betas,
                self.design,
                self.rows_to_obs,
                self.rows_to_nests]
        kwargs = {"chosen_row_to_obs": self.chosen_row_to_obs,
                  "return_type": "long_and_chosen_probs"}

        probability_results = general_calc_probabilities(*args, **kwargs)

        return probability_results
1305267
private void doPrecalculateProcess() {
		if (discreteProcess != null && discreteProcess.length != 0) {
			return;
		}

		final int numberOfPaths			= this.getNumberOfPaths();
		final int numberOfFactors		= this.getNumberOfFactors();
		final int numberOfComponents	= this.getNumberOfComponents();

		// Allocate Memory
		discreteProcess			= new RandomVariable[getTimeDiscretization().getNumberOfTimeSteps() + 1][getNumberOfComponents()];
		discreteProcessWeights	= new RandomVariable[getTimeDiscretization().getNumberOfTimeSteps() + 1];

		// Set initial Monte-Carlo weights
		discreteProcessWeights[0] = stochasticDriver.getRandomVariableForConstant(1.0 / numberOfPaths);

		// Set initial value
		RandomVariable[] initialState = getInitialState();
		final RandomVariable[] currentState = new RandomVariable[numberOfComponents];
		for (int componentIndex = 0; componentIndex < numberOfComponents; componentIndex++) {
			currentState[componentIndex] = initialState[componentIndex];
			discreteProcess[0][componentIndex] = applyStateSpaceTransform(componentIndex, currentState[componentIndex]);
		}

		/*
		 * Evolve the process using an Euler scheme.
		 * The evolution is performed multi-threadded.
		 * Each component of the vector runs in its own thread.
		 */
		executor = Executors.newCachedThreadPool();

		// Evolve process
		for (int timeIndex2 = 1; timeIndex2 < getTimeDiscretization().getNumberOfTimeSteps()+1; timeIndex2++) {
			final int timeIndex = timeIndex2;
			// Generate process from timeIndex-1 to timeIndex
			final double deltaT = getTime(timeIndex) - getTime(timeIndex - 1);

			// Fetch drift vector
			final RandomVariable[] drift;
			try {
				drift = getDrift(timeIndex - 1, discreteProcess[timeIndex - 1], null);
			}
			catch(Exception e) {
				throw new RuntimeException("Drift calculaton failed at time index " + timeIndex + " (time=" + getTime(timeIndex - 1) + ") . See cause of this exception for details.", e);
			}

			// Fetch brownianIncrement vector
			final RandomVariable[] brownianIncrement	= stochasticDriver.getIncrement(timeIndex - 1);

			// Calculate new realization
			ArrayList<Future<RandomVariable>> discreteProcessAtCurrentTimeIndex = new ArrayList<>(numberOfComponents);
			for (int componentIndex2 = 0; componentIndex2 < numberOfComponents; componentIndex2++) {
				final int componentIndex = componentIndex2;

				final RandomVariable	driftOfComponent	= drift[componentIndex];

				// Check if the component process has stopped to evolve
				if (driftOfComponent == null) {
					discreteProcessAtCurrentTimeIndex.add(componentIndex, null);
					continue;
				}

				Callable<RandomVariable> worker = new  Callable<RandomVariable>() {
					@Override
					public RandomVariable call() {
						if(scheme == Scheme.EULER_FUNCTIONAL) {
							currentState[componentIndex] = applyStateSpaceTransformInverse(componentIndex, discreteProcess[timeIndex - 1][componentIndex]);
						}

						RandomVariable[]	factorLoadings		= getFactorLoading(timeIndex - 1, componentIndex, discreteProcess[timeIndex - 1]);

						// Check if the component process has stopped to evolve
						if (factorLoadings == null) {
							return null;
						}

						// Apply drift
						if(driftOfComponent != null) {
							currentState[componentIndex] = currentState[componentIndex].addProduct(driftOfComponent, deltaT);
						}

						// Apply diffusion
						currentState[componentIndex] = currentState[componentIndex].addSumProduct(factorLoadings, brownianIncrement);

						// Transform the state space to the value space and return it.
						return applyStateSpaceTransform(componentIndex, currentState[componentIndex]).cache();
					}
				};


				/*
				 * Optional multi-threadding (asyncronous calculation of the components)
				 */
				Future<RandomVariable> result = null;
				try {
					if(isUseMultiThreadding) {
						result = executor.submit(worker);
					} else {
						result = new FutureWrapper<>(worker.call());
					}
				} catch (Exception e) {
					throw new RuntimeException("Euler step failed at time index " + timeIndex + " (time=" + getTime(timeIndex) + "). See cause of this exception for details.", e);
				}

				// The following line will add the result of the calculation to the vector discreteProcessAtCurrentTimeIndex
				discreteProcessAtCurrentTimeIndex.add(componentIndex, result);
			}

			// Fetch results and move to discreteProcess[timeIndex]
			for (int componentIndex = 0; componentIndex < numberOfComponents; componentIndex++) {
				try {
					Future<RandomVariable> discreteProcessAtCurrentTimeIndexAndComponent = discreteProcessAtCurrentTimeIndex.get(componentIndex);
					if(discreteProcessAtCurrentTimeIndexAndComponent != null) {
						discreteProcess[timeIndex][componentIndex] = discreteProcessAtCurrentTimeIndexAndComponent.get().cache();
					} else {
						discreteProcess[timeIndex][componentIndex] = discreteProcess[timeIndex-1][componentIndex];
					}
				} catch (InterruptedException e) {
					throw new RuntimeException("Euler step failed at time index " + timeIndex + " (time=" + getTime(timeIndex) + "). See cause of this exception for details.", e);
				} catch (ExecutionException e) {
					throw new RuntimeException("Euler step failed at time index " + timeIndex + " (time=" + getTime(timeIndex) + "). See cause of this exception for details.", e);
				}
			}

			if (scheme == Scheme.PREDICTOR_CORRECTOR) {
				// Apply corrector step to realizations at next time step

				RandomVariable[] driftWithPredictor = getDrift(timeIndex - 1, discreteProcess[timeIndex], null);

				for (int componentIndex = 0; componentIndex < getNumberOfComponents(); componentIndex++) {
					RandomVariable driftWithPredictorOfComponent		= driftWithPredictor[componentIndex];
					RandomVariable driftWithoutPredictorOfComponent	= drift[componentIndex];

					if (driftWithPredictorOfComponent == null || driftWithoutPredictorOfComponent == null) {
						continue;
					}

					// Calculated the predictor corrector drift adjustment
					RandomVariable driftAdjustment = driftWithPredictorOfComponent.sub(driftWithoutPredictorOfComponent).div(2.0).mult(deltaT);

					// Add drift adjustment
					currentState[componentIndex] = currentState[componentIndex].add(driftAdjustment);

					// Re-apply state space transform
					discreteProcess[timeIndex][componentIndex] = applyStateSpaceTransform(componentIndex, currentState[componentIndex]);
				} // End for(componentIndex)
			} // End if(scheme == Scheme.PREDICTOR_CORRECTOR)

			// Set Monte-Carlo weights
			discreteProcessWeights[timeIndex] = discreteProcessWeights[timeIndex - 1];
		} // End for(timeIndex)

		try {
			executor.shutdown();
		}
		catch(SecurityException e) {
			// @TODO Improve exception handling here
		}
	}
1013702
public static Map.Entry<Object, Object> bayes(DataTable2D payoffMatrix, AssociativeArray eventProbabilities) {
        if(payoffMatrix.isValid()==false) {
            throw new IllegalArgumentException("The payoff matrix does not have a rectangular format.");
        }
        
        AssociativeArray expectedPayoffs = new AssociativeArray();
        
        for(Map.Entry<Object, AssociativeArray> entry : payoffMatrix.entrySet()) {
            Object event = entry.getKey();
            AssociativeArray optionList = entry.getValue();
            for(Map.Entry<Object, Object> entry2 : optionList.entrySet()) {
                Object option = entry2.getKey();
                Double payoff = TypeInference.toDouble(entry2.getValue());
                
                Double value = expectedPayoffs.getDouble(option);
                if(value==null) {
                    value=0.0;
                }
                expectedPayoffs.put(option, value + payoff*eventProbabilities.getDouble(event));
            }
        }
        
        Map.Entry<Object, Object> entry = MapMethods.selectMaxKeyValue(expectedPayoffs);
        return entry;
    }
156072
def _calculate_format(self):
        """"""
        _format = self.format_param if self.format_param else self.format
        if self.config['options'].get('format'):
            _format = self.format_js2py(self.config['options'].get('format'))
        else:
            self.config['options']['format'] = self.format_py2js(_format)
        return _format
740739
def calculate_probabilities(tokens)
      # P(class|words) = P(w1,...,wn|class) * P(class) / P(w1,...,wn)
      #                = argmax P(w1,...,wn|class) * P(class)
      #
      # P(wi|class) = (count(wi, class) + k)/(count(w,class) + kV)
      prob_numerator = {}
      v_size = vocab.size

      cat_prob = Math.log(1 / data.categories.count.to_f)
      total_example_count = data.total_examples.to_f

      data.each do |category|
        unless assume_uniform
          cat_prob = Math.log(data.example_count(category) / total_example_count)
        end

        log_probs = 0
        denominator = (data.token_count(category) + @k * v_size).to_f
        tokens.each do |token|
          numerator = data.count_of_token_in_category(category, token) + @k
          log_probs += Math.log( numerator / denominator )
        end
        prob_numerator[category] = log_probs + cat_prob
      end
      normalize(prob_numerator)
    end
577784
def get_model(self):
        
        if self.probnet.get('type') == "BayesianNetwork":
            model = BayesianModel()
            model.add_nodes_from(self.probnet['Variables'].keys())
            model.add_edges_from(self.probnet['edges'].keys())

            tabular_cpds = []
            cpds = self.probnet['Potentials']
            for cpd in cpds:
                var = list(cpd['Variables'].keys())[0]
                states = self.probnet['Variables'][var]['States']
                evidence = cpd['Variables'][var]
                evidence_card = [len(self.probnet['Variables'][evidence_var]['States'])
                                 for evidence_var in evidence]
                arr = list(map(float, cpd['Values'].split()))
                values = np.array(arr)
                values = values.reshape((len(states), values.size//len(states)))
                tabular_cpds.append(TabularCPD(var, len(states), values, evidence, evidence_card))

            model.add_cpds(*tabular_cpds)

            variables = model.nodes()
            for var in variables:
                for prop_name, prop_value in self.probnet['Variables'][var].items():
                    model.node[var][prop_name] = prop_value
            edges = model.edges()

            if nx.__version__.startswith('1'):
                for edge in edges:
                    for prop_name, prop_value in self.probnet['edges'][edge].items():
                        model.edge[edge[0]][edge[1]][prop_name] = prop_value
            else:
                for edge in edges:
                    for prop_name, prop_value in self.probnet['edges'][edge].items():
                        model.adj[edge[0]][edge[1]][prop_name] = prop_value
            return model
        else:
            raise ValueError("Please specify only Bayesian Network.")
733888
def expect(self, use_proportions=True):
        
        changed = self.get_changed(self.partition, self.prev_partition)
        lk_table = self.generate_lktable(self.partition, changed, use_proportions)
        self.table = self.likelihood_table_to_probs(lk_table)
965747
private static void proposeSolutions(String[] dataSet, int k, int startPosition, String[] result, WebLocator webLocator) throws SolutionFoundException {

        if (k == 0) {
            validateSolution(webLocator, differences(dataSet, result));
            return;
        }

        for (int i = startPosition; i <= dataSet.length - k; i++) {
            result[result.length - k] = dataSet[i];
            proposeSolutions(dataSet, k - 1, i + 1, result, webLocator);
        }
    }
127207
function(ratios, len) {
                    if(len === undefined) throw new Error("An error occurred: len was not sent to _getCumulativeProbs");
                    if(ratios.length !== len) throw new Error("Probabilities for sample must be same length as the array to sample from");

                    var toReturn = [];

                    if(ratios !== undefined) {
                        ratios = this._v(ratios, "a");
                        if(ratios.length !== len) throw new Error("Probabilities array must be the same length as the array you are sampling from");

                        var sum = 0;
                        ratios.map(function(ratio) {
                            ratio = this._v(ratio, "nn"); // Note validating as ANY non-negative number
                            sum+= ratio;
                            toReturn.push(sum);
                        }.bind(this));

                        // Divide by total to normalize
                        for(var k=0; k<toReturn.length; k++) { toReturn[k] = toReturn[k]/sum; }
                        return toReturn
                    }
                }
508347
private void doPrecalculateProcess()
	{
		if(discreteProcess != null && discreteProcess.length != 0) {
			return;
		}

		// Allocate Memory
		discreteProcess			= new RandomVariableInterface[timeDiscretization.getNumberOfTimeSteps()+1][numberOfComponents];
		discreteProcessWeights	= new RandomVariableInterface[getTimeDiscretization().getNumberOfTimeSteps()+1];

		// Set initial Monte-Carlo weights
		discreteProcessWeights[0] = new RandomVariable(0.0, 1.0/numberOfPaths);

		// Store components
		discreteProcess[0] = getInitialValue();

		// Evolve process
		for(int timeIndex = 1; timeIndex < timeDiscretization.getNumberOfTimeSteps()+1; timeIndex++)
		{
			// Generate process at timeIndex
			double deltaT = timeDiscretization.getTime(timeIndex) - timeDiscretization.getTime(timeIndex-1);

			// Temp storage for variance and diffusion
			RandomVariableInterface[] variance   = new RandomVariableInterface[numberOfComponents];
			RandomVariableInterface[] diffusion  = new RandomVariableInterface[numberOfComponents];

			// Calculate new realization
			for(int componentIndex = numberOfComponents-1; componentIndex >= 0; componentIndex--)
			{
				// Calculate diffusion

				// Temp storage for variance and diffusion
				RandomVariableInterface varianceOfComponent  = new RandomVariable(getTime(timeIndex-1),0.0);
				RandomVariableInterface diffusionOfComponent = new RandomVariable(getTime(timeIndex-1),0.0);

				// Generate values for diffusionOfComponent and varianceOfComponent
				for(int factor=0; factor<numberOfFactors; factor++) {
					RandomVariableInterface factorLoading       = getFactorLoading(timeIndex-1, factor, componentIndex, null);
					RandomVariableInterface brownianIncrement   = brownianMotion.getBrownianIncrement(timeIndex-1,factor);

					varianceOfComponent = varianceOfComponent.addProduct(factorLoading, factorLoading);
					diffusionOfComponent = diffusionOfComponent.addProduct(factorLoading, brownianIncrement);
				}

				variance[componentIndex] = varianceOfComponent;
				diffusion[componentIndex] = diffusionOfComponent;
			}

			RandomVariableInterface[] drift;
			if(scheme == Scheme.PREDICTOR_USING_LASTREALIZATION) {
				drift = getDrift(timeIndex-1, discreteProcess[timeIndex-1], discreteProcess[timeIndex]);
			} else {
				drift = getDrift(timeIndex-1, discreteProcess[timeIndex-1], null                      );
			}

			// Calculate drift
			for(int componentIndex = numberOfComponents-1; componentIndex >= 0; componentIndex--)
			{
				RandomVariableInterface driftOfComponent  	= drift[componentIndex];
				RandomVariableInterface varianceOfComponent			= variance[componentIndex];
				RandomVariableInterface diffusionOfComponent		= diffusion[componentIndex];

				if(driftOfComponent == null) {
					discreteProcess[timeIndex][componentIndex] = discreteProcess[timeIndex-1][componentIndex];
					continue;
				}

				// Allocate memory for on path-realizations
				double[] newRealization			= new double[numberOfPaths];

				// Euler Scheme
				RandomVariableInterface previouseRealization		= discreteProcess[timeIndex-1][componentIndex];

				// Generate values
				for(int pathIndex = 0; pathIndex < numberOfPaths; pathIndex++)
				{
					double previousValue	= previouseRealization.get(pathIndex);
					double driftOnPath		= driftOfComponent.get(pathIndex);
					double varianceOnPath	= varianceOfComponent.get(pathIndex);
					double diffusionOnPath	= diffusionOfComponent.get(pathIndex);

					// The scheme
					newRealization[pathIndex]	 = previousValue * Math.exp(driftOnPath * deltaT - 0.5 * varianceOnPath * deltaT + diffusionOnPath);
				}

				// Store components
				discreteProcess[timeIndex][componentIndex] = new RandomVariable(getTime(timeIndex),newRealization);
			}

			if(scheme == Scheme.PREDICTOR_USING_EULERSTEP) {
				RandomVariableInterface[] newRealization = new RandomVariable[numberOfComponents];

				// Note: This is actually more than a predictor corrector: The drift of componentIndex already uses the corrected predictor from the previous components
				drift = getDrift(timeIndex-1, discreteProcess[timeIndex-1], discreteProcess[timeIndex]);

				// Apply corrector step to realizations at next time step
				for(int componentIndex = 0; componentIndex < numberOfComponents; componentIndex++)
				{
					RandomVariableInterface driftOfComponent	= drift[componentIndex];
					RandomVariableInterface varianceOfComponent			= variance[componentIndex];
					RandomVariableInterface diffusionOfComponent		= diffusion[componentIndex];

					// Euler Scheme with corrected drift
					RandomVariableInterface previouseRealization 	= discreteProcess[timeIndex-1][componentIndex];

					// The scheme
					// newValue = previousValue * Math.exp(driftValue * deltaT - 0.5 * varianceOnPath * deltaT + diffusionOnPath);
					newRealization[componentIndex] = previouseRealization.mult((driftOfComponent.mult(deltaT).sub(varianceOfComponent.mult(0.5 * deltaT)).add(diffusionOfComponent)).exp());
				} // End for(componentIndex)

				// Store predictor-corrector corrected process.
				discreteProcess[timeIndex] = newRealization;
			} // End if(scheme == LogNormalProcess.SCHEME_PREDICTOR_USES_EULER)

			// Set Monte-Carlo weights (since there is no Monte-Carlo weighting, the weights remain the same (namely 1.0/numberOfPaths).
			discreteProcessWeights[timeIndex] = discreteProcessWeights[timeIndex-1];
		} // End for(timeIndex)
	}
1267828
private void processOptions(OptionSet options) {
    Pseudorandom.get().setSeed(options.valueOf(randomSeed));

    if (opts.contains(CommonOptions.MAP_REDUCE)) {
      MapReduceConfiguration.setMapReduceExecutor(new LocalMapReduceExecutor(
          options.valueOf(mrMaxThreads), options.valueOf(mrMaxBatchesPerThread)));
    }

    if (opts.contains(CommonOptions.STOCHASTIC_GRADIENT) || opts.contains(CommonOptions.LBFGS)) {
      LogFunction log = null;
      if (parsedOptions.has(logBrief)) {
        log = new NullLogFunction();
      } else {
         log = new DefaultLogFunction(parsedOptions.valueOf(logInterval), false,
             options.valueOf(logParametersInterval), options.valueOf(logParametersDir));
      }
      LogFunctions.setLogFunction(log);
    }
  }
961078
def choose_labels(alternatives):
    
    if not alternatives:
        raise ValueError

    if not isinstance(alternatives, list):
        raise TypeError

    choice_map = OrderedDict(
        ('{}'.format(i), value) for i, value in enumerate(alternatives, 1)
    )
    # prepend a termination option
    input_terminator = '0'
    choice_map.update({input_terminator: '<done>'})
    choice_map.move_to_end('0', last=False)

    choice_indexes = choice_map.keys()

    choice_lines = ['{} - {}'.format(*c) for c in choice_map.items()]
    prompt = '\n'.join(
        (
            'Select labels:',
            '\n'.join(choice_lines),
            'Choose from {}'.format(', '.join(choice_indexes)),
        )
    )

    user_choices = set()
    user_choice = None

    while not user_choice == input_terminator:
        if user_choices:
            note('Selected labels: [{}]'.format(', '.join(user_choices)))

        user_choice = click.prompt(
            prompt, type=click.Choice(choice_indexes), default=input_terminator
        )
        done = user_choice == input_terminator
        new_selection = user_choice not in user_choices
        nothing_selected = not user_choices

        if not done and new_selection:
            user_choices.add(choice_map[user_choice])

        if done and nothing_selected:
            error('Please select at least one label')
            user_choice = None

    return user_choices
816368
def __select_alternatives (self, property_set_, debug):
        
        # When selecting alternatives we have to consider defaults,
        # for example:
        #    lib l : l.cpp : <variant>debug ;
        #    lib l : l_opt.cpp : <variant>release ;
        # won't work unless we add default value <variant>debug.
        assert isinstance(property_set_, property_set.PropertySet)
        assert isinstance(debug, int)  # also matches bools

        property_set_ = property_set_.add_defaults ()

        # The algorithm: we keep the current best viable alternative.
        # When we've got new best viable alternative, we compare it
        # with the current one.
        best = None
        best_properties = None

        if len (self.alternatives_) == 0:
            return None

        if len (self.alternatives_) == 1:
            return self.alternatives_ [0]

        if debug:
            print "Property set for selection:", property_set_

        for v in self.alternatives_:
            properties = v.match (property_set_, debug)

            if properties is not None:
                if not best:
                    best = v
                    best_properties = properties

                else:
                    if b2.util.set.equal (properties, best_properties):
                        return None

                    elif b2.util.set.contains (properties, best_properties):
                        # Do nothing, this alternative is worse
                        pass

                    elif b2.util.set.contains (best_properties, properties):
                        best = v
                        best_properties = properties

                    else:
                        return None

        return best
793664
def compare(self, other, analysis_set, output_directory, unique_ajps, verbose = True, compile_pdf = True):
        
        self_unique_name = self.get_definitive_name(unique_ajps)
        other_unique_name = other.get_definitive_name(unique_ajps)

        output_directory = os.path.join(output_directory, os.path.join(self_unique_name, other_unique_name) )
        assert( not os.path.isdir( output_directory ) )

        subplot_directory = os.path.join(output_directory, 'plots')
        if not os.path.isdir(subplot_directory):
            os.makedirs(subplot_directory)

        report = lr.LatexReport( table_of_contents = False )

        # Construct dataframe comparing our predictions to other's predictions
        both_predictions = pandas.concat(
            [
                self.add_identifying_columns_to_df(self.dataframe[['Predicted']], unique_ajps),
                other.add_identifying_columns_to_df(other.dataframe[['Predicted']], unique_ajps),
            ],
            join = 'outer',
        ).sort_index()
        both_predictions_subtracted = subtract_row_pairs_for_display(
            both_predictions,
            output_csv = os.path.join(output_directory, 'predictions_v_predictions.csv'),
            merge_df = self.dataframe,
            verbose = verbose,
        )

        # Construct dataframe comparing our diff with experimental values to other's
        self_diff = self.get_pred_minus_exp_dataframe(analysis_set, unique_ajps)
        other_diff = other.get_pred_minus_exp_dataframe(analysis_set, unique_ajps)
        diffs_df = pandas.concat(
            [self_diff, other_diff],
            join = 'outer',
        )

        diffs_df = subtract_row_pairs_for_display(
            diffs_df,
            output_csv = os.path.join(output_directory, 'diffs_v_diffs.csv'),
            merge_df = self.dataframe,
            verbose = verbose,
        )

        report.set_title_page(
            '%s vs %s' % (
                self.get_definitive_name(unique_ajps, join_character = '\n'),
                other.get_definitive_name(unique_ajps, join_character = '\n')
            )
        )
        predictions_v_predictions_df = self.dataframe[['Predicted']].merge(
            other.dataframe[['Predicted']],
            left_index = True,
            right_index = True,
        )
        predictions_v_predictions_df.columns = [self_unique_name, other_unique_name]
        report.add_plot( general_matplotlib.make_corr_plot(predictions_v_predictions_df, predictions_v_predictions_df.columns.values[0], predictions_v_predictions_df.columns.values[1], output_directory = subplot_directory, plot_title = 'Prediction comparison', axis_label_size = 8.0, output_name = 'vs_scatter', fig_height = 7, fig_width = 8, verbose = verbose, plot_11_line = True ), plot_title = 'Experimental vs. Predicted scatterplot (with density binning)' )

        diff_v_diff_dataframe = self.get_pred_minus_exp_dataframe(analysis_set).merge(
            other.get_pred_minus_exp_dataframe(analysis_set),
            left_index = True,
            right_index = True,
        )
        report.add_section_page( title = 'Plots' )
        diff_v_diff_dataframe.columns = [self_unique_name, other_unique_name]
        report.add_plot( general_matplotlib.make_corr_plot(diff_v_diff_dataframe, diff_v_diff_dataframe.columns.values[0], diff_v_diff_dataframe.columns.values[1], output_directory = subplot_directory, plot_title = 'Error v. Error', axis_label_size = 7.0, output_name = 'diff_vs_scatter', fig_height = 7, fig_width = 8, verbose = verbose, plot_11_line = True ), plot_title = 'Outliers --- Error (Predicted - Experimental) v. error. \\ x-axis=%s \\ y-axis=%s' % (diff_v_diff_dataframe.columns.values[0], diff_v_diff_dataframe.columns.values[1]) )

        report.add_section_page( title = 'Tables' )

        report.content.append( lr.LatexPandasTable(
            diffs_df, float_format = float_format_2sigfig,
            caption_text = 'Outliers --- Comparison of error (Predicted - Experimental) for first prediction set (%s) vs second set of predictions (%s). Values sorted by descending absolute delta.' % (self_unique_name, other_unique_name),
        ) )

        report.content.append( lr.LatexPandasTable(
            both_predictions_subtracted, float_format = float_format_2sigfig,
            caption_text = 'Direct comparison of predicted values. Values sorted by descending absolute delta.',
        ) )

        # Get joined stats comparison dataframe
        for case_table in BenchmarkRun.make_case_description_tables(BenchmarkRun.get_stats_comparison_dataframe(
                [self, other], unique_ajps,
                output_csv = os.path.join(output_directory, 'comparison_metrics.csv'),
        )):
            report.content.append( case_table )

        report.generate_pdf_report(
            os.path.join(output_directory, 'comparison.pdf'),
            verbose = verbose,
            compile_pdf = compile_pdf,
        )
        if verbose:
            print 'Comparison report saved to:', os.path.join(output_directory, 'comparison.pdf')
        return report
1176761
def set_options(self, **kw):
        
        """
        for k, v in kw.iteritems():
            if k in self.__options:
                self.__options[k] = v
387846
def likelihood(self, outcomes, modelparams, expparams):
        
        # By calling the superclass implementation, we can consolidate
        # call counting there.
        super(DirectViewParallelizedModel, self).likelihood(outcomes, modelparams, expparams)

        # If there's less models than some threshold, just use the serial model.
        # By default, we'll set that threshold to be the number of engines * 10.
        if modelparams.shape[0] <= self._serial_threshold:
            return self.underlying_model.likelihood(outcomes, modelparams, expparams)
        
        if self._dv is None:
            raise RuntimeError(
                "No direct view provided; this may be because the instance was "
                "loaded from a pickle or NumPy saved array without providing a "
                "new direct view."
            )

        # Need to decorate with interactive to overcome namespace issues with
        # remote engines.
        @interactive
        def serial_likelihood(mps, sm, os, eps):
            return sm.likelihood(os, mps, eps)

        # TODO: check whether there's a better way to pass the extra parameters
        # that doesn't use so much memory.
        # The trick is that serial_likelihood will be pickled, so we need to be
        # careful about closures.
        L = self._dv.map_sync(
            serial_likelihood,
            np.array_split(modelparams, self.n_engines, axis=0),
            [self.underlying_model] * self.n_engines,
            [outcomes] * self.n_engines,
            [expparams] * self.n_engines
        )

        return np.concatenate(L, axis=1)
1106786
def _calc_hypothesis_probability(hypothesis):
    
    prob = 0.0
    for symbol, seg in zip(hypothesis['symbols'], hypothesis['segmentation']):
        # symbol_latex = symbol['symbol'].split(";")[1]
        # TODO: Does p_strokes really improve the system?
        prob += symbol['probability']  # * p_strokes(symbol_latex, len(seg))

    # Use language model to update probabilities
    pure_symbols = [symbol['symbol'].split(";")[1]
                    for symbol in hypothesis['symbols']]
    pure_symbols = ["<s>"] + pure_symbols + ["</s>"]
    lm_prob = language_model.get_probability(pure_symbols)
    hypothesis['lm_probability'] = 2**lm_prob
    return (prob * float(hypothesis['lm_probability']) *
            (1.0 / len(hypothesis['segmentation'])))