Calculates XIRR using Newton method
 @return [BigDecimal]
 @param guess [Float]
764175
def xirr guess, options
      func = Function.new(self, :xnpv)
      rate = [guess || cf.irr_guess]
      begin
        nlsolve(func, rate)
        (rate[0] <= -1 || rate[0].nan?) ? nil : rate[0].round(Xirr::PRECISION)

          # rate[0].round(Xirr::PRECISION)
      rescue
        nil
      end
    end
352938
def xstep(self):
        
        """

        ngsit = 0
        gsrrs = np.inf
        YU = self.Y - self.U
        SYU = self.S + YU[..., -1]
        YU[..., -1] = 0.0
        ATYU = self.cnst_AT(YU)
        while gsrrs > self.opt['GSTol'] and ngsit < self.opt['MaxGSIter']:
            self.X = self.GaussSeidelStep(
                SYU, self.X, ATYU, 1.0, self.lcw, 1.0)
            gsrrs = sl.rrs(
                self.cnst_AT(self.cnst_A(self.X)),
                self.cnst_AT(self.cnst_c() - self.cnst_B(self.Y) - self.U)
            )
            ngsit += 1

        self.xs = (ngsit, gsrrs)
1050734
def predict(self, X):
        
        X_ = self._check_array(X)
        return exp(dot(X_, self._coef))
445700
function lnprior(theta) {
  var m = theta[0], b = theta[1], t = theta[2];
  if (0.0 < m && m < 1.0 && 0.0 < b && b < 10.0 && 0.0 < t && t < 100.0) {
    return 0.0;
  }
  return -Infinity;
}
159465
def _initial_guess(self, countsmat):
        

        if self.theta_ is not None:
            return self.theta_

        if self.guess == 'log':
            transmat, pi = _transmat_mle_prinz(countsmat)
            K = np.real(scipy.linalg.logm(transmat)) / self.lag_time

        elif self.guess == 'pseudo':
            transmat, pi = _transmat_mle_prinz(countsmat)
            K = (transmat - np.eye(self.n_states_)) / self.lag_time

        elif isinstance(self.guess, np.ndarray):
            pi = _solve_ratemat_eigensystem(self.guess)[1][:, 0]
            K = self.guess

        S = np.multiply(np.sqrt(np.outer(pi, 1/pi)), K)
        sflat = np.maximum(S[np.triu_indices_from(countsmat, k=1)], 0)
        theta0 = np.concatenate((sflat, np.log(pi)))
        return theta0
106173
def guesser(types=GUESS_TYPES, strict=False):
    """"""
    return TypeGuesser(types=types, strict=strict)
796914
private void calculateCL(double[] x) {
    if (values != null) {
      rvfcalculate(x);
      return;
    }
    //System.out.println("Checking at: "+x[0]+" "+x[1]+" "+x[2]);
    value = 0.0;
    if (derivative == null) {
      derivative = new double[x.length];
    } else {
      Arrays.fill(derivative, 0.0);
    }

    if (derivativeNumerator == null) {
      derivativeNumerator = new double[x.length];
      //use dataIterable if data is null & vice versa
      if(data != null) {
        for (int d = 0; d < data.length; d++) {
          //         if (d == testMin) {
          //           d = testMax - 1;
          //           continue;
          //         }
          int[] features = data[d];
          for (int f = 0; f < features.length; f++) {
            int i = indexOf(features[f], labels[d]);
            if (dataweights == null) {
              derivativeNumerator[i] -= 1;
            } else {
              derivativeNumerator[i] -= dataweights[d];
            }
          }
        }
      }
      //TODO: Make sure this work as expected!!
      else if(dataIterable != null) {
        //int index = 0;
        for (Datum<L, F> datum : dataIterable) {
          //         if (d == testMin) {
          //           d = testMax - 1;
          //           continue;
          //         }
          Collection<F> features = datum.asFeatures();
          for (F feature : features) {
            int i = indexOf(featureIndex.indexOf(feature), labelIndex.indexOf(datum.label()));
            if (dataweights == null) {
              derivativeNumerator[i] -= 1;
            } /*else {
              derivativeNumerator[i] -= dataweights[index];
            }*/
          }
        }
      }
      else {
        System.err.println("Both were null!  Couldn't calculate.");
        System.exit(-1);
      }
    }
    copy(derivative, derivativeNumerator);
    //    Arrays.fill(derivative, 0.0);
    double[] sums = new double[numClasses];
    double[] probs = new double[numClasses];
    //    double[] counts = new double[numClasses];
    //    Arrays.fill(counts, 0.0);
    
    Iterator<Datum<L, F>> iter = null;
    int d = -1;
    if(useIterable)
      iter = dataIterable.iterator();
    Datum<L, F> datum = null;
    while(true){
      if(useIterable) {
        if(!iter.hasNext()) break;
        datum = iter.next();
      } else {
        d++;
        if(d >= data.length) break;
      }

      //       if (d == testMin) {
      //         d = testMax - 1;
      //         continue;
      //       }

      // activation
      Arrays.fill(sums, 0.0);
      double total = 0;
      if(!useIterable) {
        int[] featuresArr = data[d];

        for (int c = 0; c < numClasses; c++) {
          for (int f = 0; f < featuresArr.length; f++) {
            int i = indexOf(featuresArr[f], c);
            sums[c] += x[i];
          }
        }
        // expectation (slower routine replaced by fast way)
        // double total = Double.NEGATIVE_INFINITY;
        // for (int c=0; c<numClasses; c++) {
        //   total = SloppyMath.logAdd(total, sums[c]);
        // }
        total = ArrayMath.logSum(sums);
        for (int c = 0; c < numClasses; c++) {
          probs[c] = Math.exp(sums[c] - total);
          if (dataweights != null) {
            probs[c] *= dataweights[d];
          }
          for (int f = 0; f < featuresArr.length; f++) {
            int i = indexOf(featuresArr[f], c);
            derivative[i] += probs[c];
          }
        }
      } else {
        Collection<F> features = datum.asFeatures();
        for (int c = 0; c < numClasses; c++) {
          for (F feature : features) {
            int i = indexOf(featureIndex.indexOf(feature), c);
            sums[c] += x[i];
          }
        }
        // expectation (slower routine replaced by fast way)
        // double total = Double.NEGATIVE_INFINITY;
        // for (int c=0; c<numClasses; c++) {
        //   total = SloppyMath.logAdd(total, sums[c]);
        // }
        total = ArrayMath.logSum(sums);
        for (int c = 0; c < numClasses; c++) {
          probs[c] = Math.exp(sums[c] - total);
          if (dataweights != null) {
            probs[c] *= dataweights[d];
          }
          for (F feature : features) {
            int i = indexOf(featureIndex.indexOf(feature), c);
            derivative[i] += probs[c];
          }
        }
      }

      int labelindex;
      if(useIterable)
        labelindex = labelIndex.indexOf(datum.label());
      else 
        labelindex = labels[d];
      double dV = sums[labelindex] - total;
      if (dataweights != null) {
        dV *= dataweights[d];
      }
      value -= dV;
      
    }
    value += prior.compute(x, derivative);
  }
706589
public BigDecimal getGuesses()
    {
        final Double guesses_tmp = Math.pow(2, getEntropy());
        return new BigDecimal(guesses_tmp.isInfinite() ? Double.MAX_VALUE : guesses_tmp).setScale(0, RoundingMode.HALF_UP);
    }
495937
def calculate_a(self):
        
        big_a = pow(self.g, self.small_a_value, self.big_n)
        # safety check
        if (big_a % self.big_n) == 0:
            raise ValueError('Safety check for A failed')
        return big_a
1202093
private double rdist(double[] x1, double[] x2) {
        double d = 0.0;
        for (int i = 0; i < x1.length; i++) {
            double t = x1[i] - x2[i];
            d += t * t;
        }
        return Math.sqrt(d);
    }
261330
static double usingXAndYTables(final double[] xArr, final double[] yArr,
      final double x) {
    assert (xArr.length >= 4) && (xArr.length == yArr.length);
    if ((x < xArr[0]) || (x > xArr[xArr.length - 1])) {
      throw new SketchesArgumentException("X value out of range: " + x);
    }
    if (x == xArr[xArr.length - 1]) {
      return yArr[yArr.length - 1]; // corner case
    }
    final int offset = findStraddle(xArr, x); //uses recursion
    assert (offset >= 0) && (offset <= (xArr.length - 2));
    if (offset == 0) {
      return interpolateUsingXAndYTables(xArr, yArr, offset, x); // corner case
    }
    if (offset == (xArr.length - 2)) {
      return interpolateUsingXAndYTables(xArr, yArr, offset - 2, x); // corner case
    }
    return interpolateUsingXAndYTables(xArr, yArr, offset - 1, x);
  }
299003
def interpolator(self, x, values):
        
        # hacking the barycentric interpolator by computing the weights in advance
        p = Bary([0.])
        N = len(values)
        weights = np.ones(N)
        weights[0] = .5
        weights[1::2] = -1
        weights[-1] *= .5
        p.wi = weights
        p.xi = x
        p.set_yi(values)
        return p
397700
def likelihood(self, x, cl):
        

        # sha = x.shape
        # xr = x.reshape(-1, sha[-1])
        # outsha = sha[:-1]
        # from PyQt4.QtCore import pyqtRemoveInputHook
        # pyqtRemoveInputHook()
        logger.debug("likel " + str(x.shape))
        if self.modelparams["type"] == "gmmsame":

            px = self.mdl[cl].score_samples(x)

        # todo ošetřit více dimenzionální fv
        # px = px.reshape(outsha)
        elif self.modelparams["type"] == "kernel":
            px = self.mdl[cl].score_samples(x)
        elif self.modelparams["type"] == "gaussian_kde":
            # print x
            # np.log because it is likelihood
            # @TODO Zde je patrně problém s reshape
            # old
            # px = np.log(self.mdl[cl](x.reshape(-1)))
            # new
            px = np.log(self.mdl[cl](x))
            # px = px.reshape(outsha)
            # from PyQt4.QtCore import pyqtRemoveInputHook
            # pyqtRemoveInputHook()
        elif self.modelparams["type"] == "dpgmm":
            # todo here is a hack
            # dpgmm z nějakého důvodu nefunguje pro naše data
            # vždy natrénuje jednu složku v blízkosti nuly
            # patrně to bude mít něco společného s parametrem alpha
            # přenásobí-li se to malým číslem, zázračně to chodí
            logger.warning(".score() replaced with .score_samples() . Check it.")
            # px = self.mdl[cl].score(x * 0.01)
            px = self.mdl[cl].score_samples(x * 0.01)
        elif self.modelparams["type"] == "stored":
            px = self.mdl[cl].score(x)
        return px
631888
def lnprior(self, X):
        
        if np.any(X < self._lower_left) or np.any(X > self._upper_right):
            return -np.inf
        else:
            return 0.0
391633
def findMax(arr):
    
    out = np.zeros(shape=arr.shape, dtype=bool)
    _calcMax(arr, out)
    return out
531567
def optimise_newton(x, a, c, tolerance=0.001):
    
    x_new = x
    x_old = x-1 # dummy value
    while np.abs(x_new - x_old).sum() > tolerance:
        x_old = x_new
        x_new = newton_update(x_old, a, c)
    return x_new
874565
def errtrapz(x, yerr):
    
    x = np.array(x)
    assert isinstance(x, np.ndarray)
    yerr = np.array(yerr)
    return 0.5 * np.sqrt((x[1] - x[0]) ** 2 * yerr[0] ** 2 +
                         np.sum((x[2:] - x[:-2]) ** 2 * yerr[1:-1] ** 2) +
                         (x[-1] - x[-2]) ** 2 * yerr[-1] ** 2)