Returns the local decision function for regression training purposes
without the bias term
@param v the index of the point to select
@return the decision function output sans bias
183237
protected double decisionFunctionR(int v)
    {
        double sum = 0;
        for (int i = 0; i < vecs.size(); i++)
            if (alphas[i] != alpha_s[i])//multipler would be zero
                sum += (alphas[i] - alpha_s[i]) * kEval(v, i);

        return sum;
    }
778110
public LocalVariable getLocalVariable(Location useLocation, int number) {
        int useLoc = useLocation.getLocation();
        if (useLoc < 0) {
            return null;
        } else {
            return getLocalVariable(useLoc, number);
        }
    }
183425
@Override
    public DataBuffer getVectorCoordinates() {
        int idx;
        if (isRowVector()) {
            idx = 1;
        } else if (isColumnVector()) {
            idx = 0;
        } else {
            throw new UnsupportedOperationException();
        }

        // FIXME: int cast
        int[] temp = new int[(int) length()];
        for (int i = 0; i < length(); i++) {
            temp[i] = getUnderlyingIndicesOf(i).getInt(idx);
        }
        return Nd4j.createBuffer(temp);
    }
643253
public static double cdf(double val, int v) {
    double x = v / (val * val + v);
    return 1 - (0.5 * BetaDistribution.regularizedIncBeta(x, v * .5, 0.5));
  }
923616
def _analyze_function(self):
        

        if not self._function.is_simprocedure \
                and not self._function.is_plt \
                and not self._variable_manager.has_function_manager(self._function.addr):
            l.warning("Please run variable recovery on %s before analyzing its calling conventions.",
                      repr(self._function))
            return None

        vm = self._variable_manager[self._function.addr]

        input_variables = vm.input_variables()

        input_args = self._args_from_vars(input_variables)

        # TODO: properly decide sp_delta
        sp_delta = self.project.arch.bytes if self.project.arch.call_pushes_ret else 0

        cc = SimCC.find_cc(self.project.arch, list(input_args), sp_delta)

        if cc is None:
            l.warning('_analyze_function(): Cannot find a calling convention that fits the given arguments.')

        return cc
284412
public TableFactor sumOut(int variable) {

    // OPTIMIZATION: This is by far the most common case, for linear chain inference, and is worth making fast
    // We can use closed loops, and not bother with using the basic iterator to loop through indices.
    // If this special case doesn't trip, we fall back to the standard (but slower) algorithm for the general case

    if (getDimensions().length == 2) {
      if (neighborIndices[0] == variable) {
        TableFactor marginalized = new TableFactor(new int[]{neighborIndices[1]}, new int[]{getDimensions()[1]});

        for (int i = 0; i < marginalized.values.length; i++) marginalized.values[i] = 0;

        // We use the stable log-sum-exp trick here, so first we calculate the max

        double[] max = new double[getDimensions()[1]];
        for (int j = 0; j < getDimensions()[1]; j++) {
          max[j] = Double.NEGATIVE_INFINITY;
        }

        for (int i = 0; i < getDimensions()[0]; i++) {
          int k = i * getDimensions()[1];
          for (int j = 0; j < getDimensions()[1]; j++) {
            int index = k + j;
            assert !Double.isNaN(values[index]);
            if (values[index] > max[j]) {
              max[j] = values[index];
            }
          }
        }

        // Then we take the sum, minus the max

        for (int i = 0; i < getDimensions()[0]; i++) {
          int k = i * getDimensions()[1];
          for (int j = 0; j < getDimensions()[1]; j++) {
            int index = k + j;
            if (Double.isFinite(max[j])) {
              if (USE_EXP_APPROX) {
                marginalized.values[j] += exp(values[index] - max[j]);
              } else {
                marginalized.values[j] += Math.exp(values[index] - max[j]);
              }
              assert !Double.isNaN(marginalized.values[j]);
            }
          }
        }

        // And now we exponentiate, and add back in the values

        for (int j = 0; j < getDimensions()[1]; j++) {
          if (Double.isFinite(max[j])) {
            marginalized.values[j] = max[j] + Math.log(marginalized.values[j]);
          } else {
            marginalized.values[j] = max[j];
          }
          assert !Double.isNaN(marginalized.values[j]);
        }

        return marginalized;
      } else {
        assert (neighborIndices[1] == variable);
        TableFactor marginalized = new TableFactor(new int[]{neighborIndices[0]}, new int[]{getDimensions()[0]});

        for (int i = 0; i < marginalized.values.length; i++) marginalized.values[i] = 0;

        // We use the stable log-sum-exp trick here, so first we calculate the max

        double[] max = new double[getDimensions()[0]];
        for (int i = 0; i < getDimensions()[0]; i++) {
          max[i] = Double.NEGATIVE_INFINITY;
        }

        for (int i = 0; i < getDimensions()[0]; i++) {
          int k = i * getDimensions()[1];
          for (int j = 0; j < getDimensions()[1]; j++) {
            int index = k + j;
            assert !Double.isNaN(values[index]);
            if (values[index] > max[i]) {
              max[i] = values[index];
            }
          }
        }

        // Then we take the sum, minus the max

        for (int i = 0; i < getDimensions()[0]; i++) {
          int k = i * getDimensions()[1];
          for (int j = 0; j < getDimensions()[1]; j++) {
            int index = k + j;
            if (Double.isFinite(max[i])) {
              if (USE_EXP_APPROX) {
                marginalized.values[i] += exp(values[index] - max[i]);
              } else {
                marginalized.values[i] += Math.exp(values[index] - max[i]);
              }
              assert !Double.isNaN(marginalized.values[i]);
            }
          }
        }

        // And now we exponentiate, and add back in the values

        for (int i = 0; i < getDimensions()[0]; i++) {
          if (Double.isFinite(max[i])) {
            marginalized.values[i] = max[i] + Math.log(marginalized.values[i]);
          } else {
            marginalized.values[i] = max[i];
          }
          assert !Double.isNaN(marginalized.values[i]);
        }

        return marginalized;
      }
    } else {
      // This is a little tricky because we need to use the stable log-sum-exp trick on top of our marginalize
      // dataflow operation.

      // First we calculate all the max values to use as pivots to prevent overflow
      TableFactor maxValues = maxOut(variable);

      // Then we do the sum against an offset from the pivots
      TableFactor marginalized = marginalize(variable, 0, (marginalizedVariableValue, assignment) -> (a, b) -> {
        double val = a;
        if (USE_EXP_APPROX) {
          assert !Double.isNaN(b);
          val += exp(b - maxValues.getAssignmentLogValue(assignment)) ;
          assert !Double.isNaN(val);
        } else {
          assert !Double.isNaN(b);
          val += Math.exp(b - maxValues.getAssignmentLogValue(assignment));
          assert !Double.isNaN(val);
        }
        assert !Double.isNaN(val);
        return val;
      });

      // Then we factor the max values back in, and
      for (int[] assignment : marginalized) {
        marginalized.setAssignmentLogValue(assignment, maxValues.getAssignmentLogValue(assignment) + Math.log(marginalized.getAssignmentLogValue(assignment)));
      }

      return marginalized;
    }
  }
652403
public static int ifloor (float v) {
        int iv = (int)v;
        return (v >= 0f || iv == v || iv == Integer.MIN_VALUE) ? iv : (iv - 1);
    }
844246
public static double toClassifierPrediction(Vector vector) {
        double max = Double.NEGATIVE_INFINITY;
        int maxIndex = 0;
        for (int i = 0; i < vector.size(); i++) {
            double curr = vector.apply(i);
            if (curr > max) {
                maxIndex = i;
                max = curr;
            }
        }

        return maxIndex;
    }
191952
protected boolean bracket() {
//		System.out.println("------------- bracket");
		// the value of alpha was passed in
		function.setInput(stp);
		if( mode != 0 ) {
			fp = function.computeFunction();
			gp = Double.NaN;
		} else {
			mode = 1;
		}

		// check for upper bounds
		if( fp > valueZero + ftol * stp *derivZero ) {
			setModeToSection(stprev, fprev, stp);
			return false;
		}
		if( fp >= fprev) {
			setModeToSection(stprev, fprev, stp);
			return false;
		}

		gp = function.computeDerivative();
		if( Math.abs(gp) <= -gtol *derivZero ) {
			return true;
		}

		// if the derivative is positive it is on the other side of the dip and has
		// been bracketed
		if( gp >= 0 ) {
			setModeToSection(stp, fp, stprev);
			return false;
		}
		
		if( stmax <= 2*stp - stprev ) {
			stprev = stp;
			gprev = gp;
			fprev = fp;
			stp = stmax;
			updated = true;
		} else {
			// use interpolation to pick the next sample point
			double temp = stp;
			stp = interpolate(2*stp - stprev, Math.min(stpmax, stp +t1*(stp - stprev)));
			stprev = temp;
			gprev = gp;
			fprev = fp;
			updated = true;
		}

		// see if it is taking significant steps
		if( checkSmallStep() ) {
			if( verbose != null )
				verbose.println("WARNING: Small steps");
			return true;
		}

		return false;
	}
642929
def obfn_gvar(self):
        

        if self.opt['gEvalY']:
            return self.Y
        else:
            return self.cnst_A(self.X) - self.cnst_c()
1297812
def obfn_fvarf(self):
        

        return self.Xf if self.opt['fEvalX'] else \
            sl.rfftn(self.Y, None, self.cri.axisN)
1139026
function (v) {
            var _vz = v.z || 0;
            return this._set((this.x < v.x) ? this.x : v.x, (this.y < v.y) ? this.y : v.y, (this.z < _vz) ? this.z : _vz);
        }
512700
public static DiscreteFactor getVariances(Collection<DiscreteFactor> featureFactors,
      int featureVariableNum) {
    DiscreteFactor means = getMeans(featureFactors, featureVariableNum);
    
    DiscreteFactor sumSquares = null;
    int numEntries = 0;
    for (DiscreteFactor featureFactor : featureFactors) {
      VariableNumMap nonFeatureVars = featureFactor.getVars().removeAll(featureVariableNum);
      numEntries += nonFeatureVars.getNumberOfPossibleAssignments();

      DiscreteFactor factorSumSquares = featureFactor.product(featureFactor)
          .marginalize(nonFeatureVars);
      if (sumSquares == null) {
        sumSquares = factorSumSquares;
      } else {
        sumSquares = sumSquares.add(factorSumSquares);
      }
    }
    
    return sumSquares.add(means.product(means).product(-1.0 * numEntries))
        .product(1.0 / numEntries);
  }
1093511
public static Double toDouble(Object v) {
        if (v == null) {
            return null;
        }
        if (v instanceof Boolean) {
            return ((Boolean) v) ? 1.0 : 0.0;
        }
        return ((Number) v).doubleValue();
    }
1330028
def local_accuracy(X, y, model_generator, method_name):
    

    def score_map(true, pred):
        """ Converts local accuracy from % of standard deviation to numerical scores for coloring.
        """

        v = min(1.0, np.std(pred - true) / (np.std(true) + 1e-8))
        if v < 1e-6:
            return 1.0
        elif v < 0.01:
            return 0.9
        elif v < 0.05:
            return 0.75
        elif v < 0.1:
            return 0.6
        elif v < 0.2:
            return 0.4
        elif v < 0.3:
            return 0.3
        elif v < 0.5:
            return 0.2
        elif v < 0.7:
            return 0.1
        else:
            return 0.0
    def score_function(X_train, X_test, y_train, y_test, attr_function, trained_model, random_state):
        return measures.local_accuracy(
            X_train, y_train, X_test, y_test, attr_function(X_test),
            model_generator, score_map, trained_model
        )
    return None, __score_method(X, y, None, model_generator, score_function, method_name)
628325
public LinearClassifier<L, F> trainClassifierV(GeneralDataset<L, F> train, GeneralDataset<L, F> validation, double min, double max, boolean accuracy) {
    labelIndex = train.labelIndex();
    featureIndex = train.featureIndex();
    this.min = min;
    this.max = max;
    heldOutSetSigma(train, validation);
    double[][] weights = trainWeights(train);
    return new LinearClassifier<L, F>(weights, train.featureIndex(), train.labelIndex());
  }
220419
def local_project(v, V, u=None):
    """"""
    dv = TrialFunction(V)
    v_ = TestFunction(V)
    a_proj = inner(dv, v_)*dx
    b_proj = inner(v, v_)*dx
    solver = LocalSolver(a_proj, b_proj)
    solver.factorize()
    if u is None:
        u = Function(V)
        solver.solve_local_rhs(u)
        return u
    else:
        solver.solve_local_rhs(u)
        return