示例#1
0
 public double calculateEntropy(Temperature temp) {
   double T = temp.getK();
   double entropy;
   if (T < 298) throw new TemperatureOutOfRangeException();
   else if (T < middleTemperature) {
     double[] a = new double[7];
     a = lowTemperatureCoefficients;
     entropy =
         a[0] * Math.log(T)
             + a[1] * T
             + a[2] * T * T / 2
             + a[3] * T * T * T / 3
             + a[4] * T * T * T * T / 4
             + a[6];
     entropy = entropy * GasConstant.getCalMolK();
     return entropy;
   } else if (T < highTemperature) {
     double[] a = new double[7];
     a = highTemperatureCoefficients;
     entropy =
         a[0] * Math.log(T)
             + a[1] * T
             + a[2] * T * T / 2
             + a[3] * T * T * T / 3
             + a[4] * T * T * T * T / 4
             + a[6];
     entropy = entropy * GasConstant.getCalMolK();
     return entropy;
   } else throw new TemperatureOutOfRangeException();
 }
示例#2
0
 public static String humanReadableByteCount(long bytes, boolean si) {
   int unit = si ? 1000 : 1024;
   if (bytes < unit) return bytes + " B";
   int exp = (int) (Math.log(bytes) / Math.log(unit));
   String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");
   return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
 }
 private NBWeights trainWeightsJL(int[][] data, int[] labels, int numFeatures, int numClasses) {
   int[] numValues = numberValues(data, numFeatures);
   double[] priors = new double[numClasses];
   double[][][] weights = new double[numClasses][numFeatures][];
   // init weights array
   for (int cl = 0; cl < numClasses; cl++) {
     for (int fno = 0; fno < numFeatures; fno++) {
       weights[cl][fno] = new double[numValues[fno]];
     }
   }
   for (int i = 0; i < data.length; i++) {
     priors[labels[i]]++;
     for (int fno = 0; fno < numFeatures; fno++) {
       weights[labels[i]][fno][data[i][fno]]++;
     }
   }
   for (int cl = 0; cl < numClasses; cl++) {
     for (int fno = 0; fno < numFeatures; fno++) {
       for (int val = 0; val < numValues[fno]; val++) {
         weights[cl][fno][val] =
             Math.log(
                 (weights[cl][fno][val] + alphaFeature)
                     / (priors[cl] + alphaFeature * numValues[fno]));
       }
     }
     priors[cl] = Math.log((priors[cl] + alphaClass) / (data.length + alphaClass * numClasses));
   }
   return new NBWeights(priors, weights);
 }
  /* Function for calculating laplacePerTerm for individual query terms */
  public static double laplacePerTerm(
      String termFreq, double docLen, double avgLen, long vocabSize, int queryWords) {

    // System.out.println("Query Words:::");

    String[] termFs = termFreq.split(" ");

    // System.out.println("TermFs::: "+ termFreq);

    double log_p_lap = 0.0;

    /*
     * if(termFs.length <= queryWords){
     *
     * for(int j=0;j<(queryWords-termFs.length); j++){ log_p_lap +=
     * Math.log(((0 + 1) / (docLen + vocabSize)); } log_p_lap+= (Math.log((0
     * + 1) / (docLen + vocabSize))) * (queryWords - termFs.length);
     *
     * }
     */
    if (termFs.length < queryWords) {
      log_p_lap += (Math.log((0 + 1) / (docLen + vocabSize))) * (queryWords - termFs.length);
    }

    for (int i = 0; i < termFs.length; i++) {

      log_p_lap += Math.log(((Integer.parseInt(termFs[i])) + 1) / (docLen + vocabSize));
    }

    return log_p_lap;
  }
    public Double eval(Double gamma) {
      double c1 = 0.0;
      double c3 = -1.0 / (double) Math.sqrt(2.0 * variance);
      double sum = 0.0;

      double cpart = -0.5 * Math.log(Math.sqrt(2.0 * Math.PI * variance));

      for (Integer i : transcripts.get(gammat)) {
        c1 += cpart;
        double pi = 0.0;

        for (int t = 0; t < fiveprime.length; t++) {
          if (transcripts.get(t).contains(i)) {
            double gammai = gammat == t ? gamma : gammas[t][gammak];
            double dit = delta(i, t);

            double pit = gammai * Math.exp(-lambda * dit);
            pi += pit;
          }
        }

        double zi = Math.log(pi);
        double err = data.values(i)[channels[gammak]] - zi;

        sum += (err * err);
      }

      return c1 + c3 * sum;
    }
    public Double eval(Double lmbda) {
      double c1 = 0.0;
      double c3 = -1.0 / (double) Math.sqrt(2.0 * variance);
      double sum = 0.0;

      double cpart = -0.5 * Math.log(Math.sqrt(2.0 * Math.PI * variance));

      for (int i = 0; i < data.size(); i++) {
        for (int k = 0; k < channels.length; k++) {
          c1 += cpart;
          double pi = 0.0;

          for (Integer t : transcripts.keySet()) {
            if (transcripts.get(t).contains(i)) {
              double dit = delta(i, t);
              double gammai = gammas[t][k];
              double pit = gammai * Math.exp(-lmbda * dit);
              pi += pit;
            }
          }

          double zi = Math.log(pi);
          double err = data.values(i)[channels[k]] - zi;

          sum += (err * err);
        }
      }

      return c1 + c3 * sum;
    }
示例#7
0
文件: SEM.java 项目: Navieclipse/KEEL
  /** Applies mutation in the new poblation */
  public void mutate() {
    int posiciones, i, j;
    double m;

    posiciones = n_genes * long_poblacion;

    if (prob_mutacion > 0)
      while (Mu_next < posiciones) {
        /* Se determina el cromosoma y el gen que corresponden a la posicion que
        se va a mutar */
        i = Mu_next / n_genes;
        j = Mu_next % n_genes;

        /* Se efectua la mutacion sobre ese gen */
        poblacion[i].mutate(j);

        /* Se marca el cromosoma mutado para su posterior evaluacion */
        poblacion[i].setEvaluated(false);

        /* Se calcula la siguiente posicion a mutar */
        if (prob_mutacion < 1) {
          m = Randomize.Rand();
          Mu_next += Math.ceil(Math.log(m) / Math.log(1.0 - prob_mutacion));
        } else Mu_next += 1;
      }

    Mu_next -= posiciones;
  }
示例#8
0
  /**
   * Calculates the sample likelihood and BIC score for i given its parents in a simple SEM model.
   */
  private double localSemScore(int i, int[] parents) {
    try {
      ICovarianceMatrix cov = getCovMatrix();
      double varianceY = cov.getValue(i, i);
      double residualVariance = varianceY;
      int n = sampleSize();
      int p = parents.length;
      int k = (p * (p + 1)) / 2 + p;
      //            int k = (p + 1) * (p + 1);
      //            int k = p + 1;
      TetradMatrix covxx = cov.getSelection(parents, parents);
      TetradMatrix covxxInv = covxx.inverse();
      TetradVector covxy = cov.getSelection(parents, new int[] {i}).getColumn(0);
      TetradVector b = covxxInv.times(covxy);
      residualVariance -= covxy.dotProduct(b);

      if (residualVariance <= 0 && verbose) {
        out.println(
            "Nonpositive residual varianceY: resVar / varianceY = "
                + (residualVariance / varianceY));
        return Double.NaN;
      }

      double c = getPenaltyDiscount();

      //            return -n * log(residualVariance) - 2 * k; //AIC
      return -n * Math.log(residualVariance) - c * k * Math.log(n);
      //            return -n * log(residualVariance) - c * k * (log(n) - log(2 * PI));
    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e);
      //            throwMinimalLinearDependentSet(parents, cov);
    }
  }
示例#9
0
 /**
  * Returns the <sup>10</sup>log() of a value
  *
  * @return the <sup>10</sup>log()
  */
 static double log10(int v) {
   double dl = 0.0;
   if (v != 0.0) {
     dl = Math.log(v) / Math.log(10);
   }
   return dl;
 }
示例#10
0
  public void addObservedResult(double result, int timeElapsed, String passCode)
      throws IllegalStateValueDataModificationException {
    if (!this.passCode.equals(passCode)) {
      throw new IllegalStateValueDataModificationException();
    }
    sum += result;
    sum2 += (result * result);

    count++;

    average = sum / count;
    double variance = Math.abs(sum2 / count - average * average);
    sdev = Math.sqrt(variance);
    sharpe = average * average / variance;

    Integer timeClass = (int) (Math.log(timeElapsed) / Math.log(2));
    Integer distClass = (int) (result / res);
    if (!dist.containsKey(timeClass)) {
      dist.put(timeClass, new TreeMap<Integer, Double>());
    }
    if (!dist.get(timeClass).containsKey(distClass)) {
      dist.get(timeClass).put(distClass, 0.0);
    }

    dist.get(timeClass).put(distClass, dist.get(timeClass).get(distClass) + 1);

    if (!collapsedDist.containsKey(distClass)) {
      collapsedDist.put(distClass, 0.0);
    }

    collapsedDist.put(distClass, collapsedDist.get(distClass) + 1);
  }
示例#11
0
  /**
   * <br>
   * In the first round,</br> <br>
   * In the paper the server is supposed to ask sensors for uncoded data.</br> <br>
   * We sent the maximum number of bits: 63 bits = "111111"</br> <br>
   * Sensor will encode in IEEE double format</br> <br>
   * Calculates the i (number of requested bits), as given in the paper</br>
   */
  @Override
  public String sendRequest(int sensor_id) {

    if (is_first_round[sensor_id] || sensor_id == 0 || round_number < M) {

      requested_bits[sensor_id] = maximum_number_of_bits_askable;

      return "111111";
    }

    double delta = code_book.getD();

    int i =
        (int)
            Math.ceil(
                (0.5
                        * (Math.log((sigma[sensor_id] * sigma[sensor_id]) / (delta * delta * P_e))
                            / Math.log(2.0)))
                    + 1);
    i = Math.min(i, maximum_number_of_bits_askable); // request not more that 63 bits
    i = Math.max(0, i); // request no less than 0 bits

    requested_bits[sensor_id] = i;

    String bit_string =
        tools.pad0ToFront(
            Integer.toBinaryString(i),
            bits_needed_to_represent_maximum_askable); // pad it to make length 6

    return tools.reverse(bit_string);
  }
 private double calcMean(
     HashMap<Integer, String> singleGeneCaseValueMap,
     String groupType,
     String profileStableId) { // group type: altered or unaltered
   switch (groupType) {
     case "altered":
       int _index_altered = 0;
       double[] alteredArray = new double[alteredSampleIds.size()];
       for (Integer alteredSampleId : alteredSampleIds) {
         if (singleGeneCaseValueMap.containsKey(alteredSampleId)) {
           if (profileStableId.indexOf("rna_seq") != -1) {
             try {
               alteredArray[_index_altered] =
                   Math.log(Double.parseDouble(singleGeneCaseValueMap.get(alteredSampleId)))
                       / Math.log(2);
             } catch (NumberFormatException e) {
               e.getStackTrace();
             }
           } else {
             try {
               alteredArray[_index_altered] =
                   Double.parseDouble(singleGeneCaseValueMap.get(alteredSampleId));
             } catch (NumberFormatException e) {
               e.getStackTrace();
             }
           }
           _index_altered += 1;
         }
       }
       return StatUtils.mean(alteredArray);
     case "unaltered":
       int _index_unaltered = 0;
       double[] unalteredArray = new double[unalteredSampleIds.size()];
       for (Integer unalteredSampleId : unalteredSampleIds) {
         if (singleGeneCaseValueMap.containsKey(unalteredSampleId)) {
           if (profileStableId.indexOf("rna_seq") != -1) {
             try {
               unalteredArray[_index_unaltered] =
                   Math.log(Double.parseDouble(singleGeneCaseValueMap.get(unalteredSampleId)))
                       / Math.log(2);
             } catch (NumberFormatException e) {
               e.getStackTrace();
             }
           } else {
             try {
               unalteredArray[_index_unaltered] =
                   Double.parseDouble(singleGeneCaseValueMap.get(unalteredSampleId));
             } catch (NumberFormatException e) {
               e.getStackTrace();
             }
           }
           _index_unaltered += 1;
         }
       }
       return StatUtils.mean(unalteredArray);
     default:
       return Double.NaN; // error
   }
 }
  private static JointClassification jointJointClassify(ssd.Document doc) {

    double[][] classprobs = new double[PartsOfSpeech.length][CATEGORIES.length];
    double[] jointprobs = new double[CATEGORIES.length];
    double[] ranks = new double[CATEGORIES.length];
    double[] classif_variances = new double[PartsOfSpeech.length];

    for (double d : jointprobs) d = 0;

    for (int i = 0; i < CATEGORIES.length; i++) ranks[i] = 0;

    JointClassification jc = new JointClassification(CATEGORIES, jointprobs);

    for (int i = 0; i < PartsOfSpeech.length; i++) {
      String pos = PartsOfSpeech[i];
      if (doc.mPosTexts.get(pos) != null) {
        JointClassification jc1 = compiledClassifiers.get(pos).classify(doc.mPosTexts.get(pos));
        for (int j = 0; j < CATEGORIES.length; j++)
          classprobs[i][j] = getCategoryConditionalProbability(CATEGORIES[j], jc1);
      }
    }

    for (int i = 0; i < classif_variances.length; i++) {
      classif_variances[i] =
          variance(classprobs[i]); // get the variance of each classifier into classif_variances
    }

    double average_variance = 0, max_classif_variance = -1, sum_variance = 0;
    for (double d : classif_variances) {
      sum_variance += d;
      if (d > max_classif_variance) max_classif_variance = d;
    }

    average_variance = sum_variance / classif_variances.length;
    // say we cheat and let the average be the same as the 'all' partofspeech
    for (int i = 0; i < PartsOfSpeech.length; i++)
      if (PartsOfSpeech[i].equals("all")) average_variance = classif_variances[i];
    // average_variance=max_classif_variance;
    /*switch this all back, write the paper, finish the presentation. WRAP THE F**K UP */
    /* No! this method achieves 67% accuracy on 20news! */

    for (int i = 0; i < CATEGORIES.length; i++)
      for (int j = 0; j < classif_variances.length; j++)
        ranks[i] += classif_variances[j] * classprobs[j][i] / sum_variance;

    double ranksum = 0;
    for (double r : ranks) ranksum += r;

    for (int i = 0; i < CATEGORIES.length; i++) ranks[i] = ranks[i] / ranksum;

    for (int i = 0; i < CATEGORIES.length; i++) ranks[i] = Math.log(ranks[i]) / Math.log(2);

    ranks = sort_with_categories(ranks);
    // the new transformed matrix is a matrix of log2 of probabilities of belonging calculated from
    // ranks
    jc = new JointClassification(CATEGORIES, ranks);

    return jc;
  }
  public boolean isIndependent(Node x, Node y, List<Node> z) {
    int[] all = new int[z.size() + 2];
    all[0] = variablesMap.get(x);
    all[1] = variablesMap.get(y);
    for (int i = 0; i < z.size(); i++) {
      all[i + 2] = variablesMap.get(z.get(i));
    }

    int sampleSize = data.get(0).rows();
    List<Double> pValues = new ArrayList<Double>();

    for (int m = 0; m < ncov.size(); m++) {
      TetradMatrix _ncov = ncov.get(m).getSelection(all, all);
      TetradMatrix inv = _ncov.inverse();
      double r = -inv.get(0, 1) / sqrt(inv.get(0, 0) * inv.get(1, 1));

      double fisherZ =
          sqrt(sampleSize - z.size() - 3.0) * 0.5 * (Math.log(1.0 + r) - Math.log(1.0 - r));
      double pValue;

      if (Double.isInfinite(fisherZ)) {
        pValue = 0;
      } else {
        pValue = 2.0 * (1.0 - RandomUtil.getInstance().normalCdf(0, 1, abs(fisherZ)));
      }

      pValues.add(pValue);
    }

    double _cutoff = alpha;

    if (fdr) {
      _cutoff = StatUtils.fdrCutoff(alpha, pValues, false);
    }

    Collections.sort(pValues);
    int index = (int) round((1.0 - percent) * pValues.size());
    this.pValue = pValues.get(index);

    //        if (this.pValue == 0) {
    //            System.out.println("Zero pvalue "+ SearchLogUtils.independenceFactMsg(x, y, z,
    // getPValue()));
    //        }

    boolean independent = this.pValue > _cutoff;

    if (verbose) {
      if (independent) {
        TetradLogger.getInstance()
            .log("independencies", SearchLogUtils.independenceFactMsg(x, y, z, getPValue()));
        //            System.out.println(SearchLogUtils.independenceFactMsg(x, y, z, getPValue()));
      } else {
        TetradLogger.getInstance()
            .log("dependencies", SearchLogUtils.dependenceFactMsg(x, y, z, getPValue()));
      }
    }

    return independent;
  }
  public void testEstimateWNoValues() throws Exception {
    double[] y = new double[] {};

    double sigma = 30;
    double[] initialW = new double[] {Math.log(.5), Math.log(.5)};

    assertEquals(1, scorer.estimate(y, initialW, 200, sigma, new double[y.length]).w0, 0.0001);
  }
  @Test
  public void testLikelihood() throws Exception {
    double[] y = NODEL_ISIZES;

    double l =
        scorer.likelihood(
            y, new double[] {Math.log(.5), Math.log(.5)}, new double[] {100, 1100}, 15);
    assertEquals(-29.90017, l, 0.0001);
  }
  @Test
  public void testEstimateW() throws Exception {
    double[] y = HET_DEL_5X_5N;

    double sigma = 30;
    double[] initialW = new double[] {Math.log(.5), Math.log(.5)};

    assertEquals(.5, scorer.estimate(y, initialW, 200, sigma, new double[y.length]).w0, 0.0001);
  }
  private double runTTest(HashMap<Integer, String> singleGeneCaseValueMap, String profileStableId)
      throws IllegalArgumentException {

    double[] unalteredArray = new double[unalteredSampleIds.size()];
    double[] alteredArray = new double[alteredSampleIds.size()];
    int _index_unaltered = 0, _index_altered = 0;

    for (Integer alteredSampleId : alteredSampleIds) {
      if (singleGeneCaseValueMap.containsKey(alteredSampleId)) {
        if (profileStableId.indexOf("rna_seq") != -1) {
          try {
            alteredArray[_index_altered] =
                Math.log(Double.parseDouble(singleGeneCaseValueMap.get(alteredSampleId)))
                    / Math.log(2);
          } catch (NumberFormatException e) {
            e.getStackTrace();
          }
        } else {
          try {
            alteredArray[_index_altered] =
                Double.parseDouble(singleGeneCaseValueMap.get(alteredSampleId));
          } catch (NumberFormatException e) {
            e.getStackTrace();
          }
        }
        _index_altered += 1;
      }
    }
    for (Integer unalteredSampleId : unalteredSampleIds) {
      if (singleGeneCaseValueMap.containsKey(unalteredSampleId)) {
        if (profileStableId.indexOf("rna_seq") != -1) {
          try {
            unalteredArray[_index_unaltered] =
                Math.log(Double.parseDouble(singleGeneCaseValueMap.get(unalteredSampleId)))
                    / Math.log(2);
          } catch (NumberFormatException e) {
            e.getStackTrace();
          }
        } else {
          try {
            unalteredArray[_index_unaltered] =
                Double.parseDouble(singleGeneCaseValueMap.get(unalteredSampleId));
          } catch (NumberFormatException e) {
            e.getStackTrace();
          }
        }
        _index_unaltered += 1;
      }
    }

    if (alteredArray.length < 2 || unalteredArray.length < 2) return Double.NaN;
    else {
      double pvalue = TestUtils.tTest(alteredArray, unalteredArray);
      return pvalue;
    }
  }
示例#19
0
  double computeEntropy(Vector v, int numValues) {
    double ent = 0;

    for (int i = 0, size = v.size(); i < size; i++) {
      double prob = ((Integer) v.elementAt(i)).intValue();
      prob /= (double) numValues;
      ent += prob * Math.log(prob) / Math.log(2);
    }
    return -ent;
  }
示例#20
0
 static double optimalCompressedLength(int[] a) {
   int max = 0;
   for (int x : a) max = Math.max(max, x);
   int[] freq = new int[max + 1];
   for (int x : a) ++freq[x];
   double optimalLength = 0;
   for (int f : freq)
     if (f > 0) optimalLength += f * Math.log((double) a.length / f) / Math.log(2) / 8;
   return optimalLength;
 }
示例#21
0
  private double errors(double N, double e, double CF) {
    // Some constants for the interpolation.
    double Val[] = {
      0,
      0.000000001,
      0.00000001,
      0.0000001,
      0.000001,
      0.00001,
      0.00005,
      0.0001,
      0.0005,
      0.001,
      0.005,
      0.01,
      0.05,
      0.10,
      0.20,
      0.40,
      1.00
    };
    double Dev[] = {
      100, 6.0, 5.61, 5.2, 4.75, 4.26, 3.89, 3.72, 3.29, 3.09, 2.58, 2.33, 1.65, 1.28, 0.84, 0.25,
      0.00
    };
    double Val0, Pr, Coeff;
    int i;

    Coeff = 0;
    i = 0;

    while (CF > Val[i]) i++;

    Coeff = Dev[i - 1] + (Dev[i] - Dev[i - 1]) * (CF - Val[i - 1]) / (Val[i] - Val[i - 1]);
    Coeff = Coeff * Coeff;

    if (e < 1E-6) return N * (1.0 - Math.exp(Math.log(CF) / N));
    else {
      if (e < 0.9999) {
        Val0 = N * (1 - Math.exp(Math.log(CF) / N));
        return (Val0 + e * (errors(N, 1.0, CF) - Val0));
      } else {
        if (e + 0.5 >= N) return (0.67 * (N - e));
        else {
          Pr =
              (e
                      + 0.5
                      + Coeff / 2
                      + Math.sqrt(Coeff * ((e + 0.5) * (1 - (e + 0.5) / N) + Coeff / 4)))
                  / (N + Coeff);
          return (N * Pr - e);
        }
      }
    }
  }
  public static double getEntropy(double[] P) {
    double entropy = 0;
    for (double p : P) if (1 / (p * Math.log(1 / p)) != 0) entropy += -p * Math.log(p);
    double psum = 0;
    for (double p : P) psum += p;
    System.err.println("Sum of probs: " + psum + "[ ");
    for (double p : P) System.err.printf("%1.2f,", p);
    System.err.println("Entropy: " + entropy);

    return entropy;
  }
示例#23
0
 String visualize() {
   int ubDepth = (int) Math.ceil(Math.log(size) / Math.log(m_order)) * elemHeight;
   int ubWidth = size * elemWidth;
   java.io.StringWriter sw = new java.io.StringWriter();
   java.io.PrintWriter pw = new java.io.PrintWriter(sw);
   pw.println("<html><head></head><body>");
   visualize(root, pw, 0, 0, ubWidth, ubDepth);
   pw.println("</body></html>");
   pw.flush();
   return sw.toString();
 }
 private double branchLLInPopsIOtree(PopsIONode node, double alpha, double beta) {
   int q = node.coalcount;
   double gamma = node.coalintensity;
   double llhood = 0.0;
   for (int i = 1; i <= q - 1; i++) {
     llhood += Math.log(alpha + i);
   }
   llhood += alpha * Math.log(beta);
   llhood -= (alpha + q) * Math.log(beta + gamma);
   return llhood;
 }
 private double calcSTDev(
     HashMap<Integer, String> singleGeneCaseValueMap, String groupType, String profileStableId) {
   switch (groupType) {
     case "altered":
       DescriptiveStatistics stats_altered = new DescriptiveStatistics();
       for (Integer alteredSampleId : alteredSampleIds) {
         if (singleGeneCaseValueMap.containsKey(alteredSampleId)) {
           if (profileStableId.indexOf("rna_seq") != -1) {
             try {
               stats_altered.addValue(
                   Math.log(Double.parseDouble(singleGeneCaseValueMap.get(alteredSampleId)))
                       / Math.log(2));
             } catch (NumberFormatException e) {
               e.getStackTrace();
             }
           } else {
             try {
               stats_altered.addValue(
                   Double.parseDouble(singleGeneCaseValueMap.get(alteredSampleId)));
             } catch (NumberFormatException e) {
               e.getStackTrace();
             }
           }
         }
       }
       return stats_altered.getStandardDeviation();
     case "unaltered":
       DescriptiveStatistics stats_unaltered = new DescriptiveStatistics();
       for (Integer unalteredSampleId : unalteredSampleIds) {
         if (singleGeneCaseValueMap.containsKey(unalteredSampleId)) {
           if (profileStableId.indexOf("rna_seq") != -1) {
             try {
               stats_unaltered.addValue(
                   Math.log(Double.parseDouble(singleGeneCaseValueMap.get(unalteredSampleId)))
                       / Math.log(2));
             } catch (NumberFormatException e) {
               e.getStackTrace();
             }
           } else {
             try {
               stats_unaltered.addValue(
                   Double.parseDouble(singleGeneCaseValueMap.get(unalteredSampleId)));
             } catch (NumberFormatException e) {
               e.getStackTrace();
             }
           }
         }
       }
       return stats_unaltered.getStandardDeviation();
     default:
       return Double.NaN; // error
   }
 }
示例#26
0
  public static void main(String[] args) {
    double delta = 0.0001;
    double sigma = 0.005;
    double P_e = 0.01;

    int i =
        (int)
            Math.ceil(
                (0.5 * (Math.log((sigma * sigma) / (delta * delta * P_e)) / Math.log(2.0))) + 1);
    i = Math.min(i, 63); // request not more that 63 bits
    i = Math.max(0, i); // request no less than 0 bits
  }
  public TopicScores getTokenDocumentDiscrepancies() {
    TopicScores scores = new TopicScores("token-doc-diff", numTopics, numTopWords);
    scores.wordScoresDefined = true;

    for (int topic = 0; topic < numTopics; topic++) {
      int[][] matrix = topicCodocumentMatrices[topic];
      TreeSet<IDSorter> sortedWords = topicSortedWords.get(topic);

      double topicScore = 0.0;

      double[] wordDistribution = new double[numTopWords];
      double[] docDistribution = new double[numTopWords];

      double wordSum = 0.0;
      double docSum = 0.0;

      int position = 0;
      Iterator<IDSorter> iterator = sortedWords.iterator();
      while (iterator.hasNext() && position < numTopWords) {
        IDSorter info = iterator.next();

        wordDistribution[position] = info.getWeight();
        docDistribution[position] = matrix[position][position];

        wordSum += wordDistribution[position];
        docSum += docDistribution[position];

        position++;
      }

      for (position = 0; position < numTopWords; position++) {
        double p = wordDistribution[position] / wordSum;
        double q = docDistribution[position] / docSum;
        double meanProb = 0.5 * (p + q);

        double score = 0.0;
        if (p > 0) {
          score += 0.5 * p * Math.log(p / meanProb);
        }
        if (q > 0) {
          score += 0.5 * q * Math.log(q / meanProb);
        }

        scores.setTopicWordScore(topic, position, score);
        topicScore += score;
      }

      scores.setTopicScore(topic, topicScore);
    }

    return scores;
  }
 public void addCrossNumericProximity(Counter<String> features, final NumericMentionExpression e) {
   List<NumericTuple> args = e.expression.arguments();
   if (args.size() > 1) {
     double multiplier = args.get(0).val / args.get(1).val;
     features.incrementCount("abs-numeric-distance-12", Math.abs(Math.log(multiplier)));
   }
   if (args.size() > 2) {
     double multiplier13 = args.get(0).val / args.get(2).val;
     double multiplier23 = args.get(1).val / args.get(2).val;
     features.incrementCount("abs-numeric-distance-13", Math.abs(Math.log(multiplier13)));
     features.incrementCount("abs-numeric-distance-23", Math.abs(Math.log(multiplier23)));
   }
 }
示例#29
0
  // Entropy(S) = - sum(1..n) [ p(i)*log(pi)}
  private double computeEntropy() {
    double sum = 0.0;
    int numTags = myTags.size();

    for (int i = 0; i < numTags; i++) {
      String tag = (String) myTags.elementAt(i);
      if (!tag.equals(boundaryTag)) {
        double probTag = getUnigramProb(tag);
        double logProbTag = Math.log(probTag) / Math.log(2.0); // Math.log is natural log, base e
        sum += probTag * logProbTag;
      }
    }
    return -sum;
  }
示例#30
0
 /**
  * specifies the function LND6 on double[] x.
  *
  * @param x double[]
  * @return double
  */
 private double evalArray(double[] x) {
   double res = Double.NEGATIVE_INFINITY;
   for (int i = 0; i < x.length; i++) {
     double gxi = Math.log(Math.abs(x[i]) + 1);
     if (gxi > res) res = gxi;
   }
   double sum = 0.0;
   for (int i = 0; i < x.length; i++) {
     sum += x[i];
   }
   sum = Math.log(Math.abs(sum) + 1);
   if (sum > res) res = sum;
   return res;
 }