Example usage for java.lang Math log10

List of usage examples for java.lang Math log10

Introduction

In this page you can find the example usage for java.lang Math log10.

Prototype

@HotSpotIntrinsicCandidate
public static double log10(double a) 

Source Link

Document

Returns the base 10 logarithm of a double value.

Usage

From source file:org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.AlleleFrequencyCalculatorUnitTest.java

@Test
public void testManyRefSamplesDontKillGoodVariant() {
    final AlleleFrequencyCalculator afCalc = new AlleleFrequencyCalculator(1, 0.1, 0.1, DEFAULT_PLOIDY);
    final List<Allele> alleles = Arrays.asList(A, B);
    final Genotype AA = genotypeWithObviousCall(DIPLOID, BIALLELIC, new int[] { 0, 2 }, EXTREMELY_CONFIDENT_PL);
    final Genotype AB = genotypeWithObviousCall(DIPLOID, BIALLELIC, new int[] { 0, 1, 1, 1 },
            EXTREMELY_CONFIDENT_PL);/*from   ww w .  j  a  v  a  2  s. c om*/
    for (final int numRef : new int[] { 1, 10, 100, 1000, 10000, 100000 }) {
        final List<Genotype> genotypeList = new ArrayList<>(Collections.nCopies(numRef, AA));
        genotypeList.add(AB);
        final VariantContext vc = makeVC(alleles, genotypeList);
        final double log10PRef = afCalc.getLog10PNonRef(vc).getLog10LikelihoodOfAFEq0();
        Assert.assertTrue(log10PRef < (-EXTREMELY_CONFIDENT_PL / 10) + Math.log10(numRef) + 1);
    }
}

From source file:statisticsintegration.StatisticsLabr.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

    List<String> Temp = new ArrayList<String>();
    List<String> check = new ArrayList<String>();
    List<Double> fnl = new ArrayList<>();
    List<String> frame = new ArrayList<String>();
    List<String> name = new ArrayList<String>();
    List<String> name2 = new ArrayList<String>();
    List<Double> frame2 = new ArrayList<Double>();
    List<Double> limitLeft = new ArrayList<>();
    List<Double> limitRight = new ArrayList<>();
    List<Double> trueLimitLeft = new ArrayList<>();
    List<Double> trueLimitRight = new ArrayList<>();
    List<Double> midpoint = new ArrayList<>();
    List<Integer> frequency = new ArrayList<>();
    List<Double> percent = new ArrayList<>();
    List<Integer> cf = new ArrayList<>();
    List<Double> cp = new ArrayList<>();

    Integer freq = 0;//ww  w. ja  v  a  2  s. c  o  m
    Double freqtot = 0.0;

    if (Categorical.isSelected() == true && Numerical.isSelected() == false) {
        for (int i = 0; i < jTable1.getRowCount(); i++) {
            frame.add((String) jTable1.getModel().getValueAt(i, 0));
        }
        Collections.sort(frame);

        Integer size = frame.size();
        System.out.println(size);
        for (Object b : frame) {
            String c = b + "";
            Temp.add(c);
        }

        for (int i = 0; i < jTable1.getRowCount(); i++) {
            for (int j = 0; j < jTable1.getColumnCount(); j++) {
                jTable1.setValueAt("", i, j);
            }
        }

        int ct = 0;
        for (Object z : frame) {
            String a = z + "";
            System.out.print(check.contains(a));
            if (!(check.contains(a))) {
                for (int i = 0; i < Temp.size(); i++) {
                    if (a.equals(Temp.get(i))) {
                        freq++;
                    }
                }
                Double freque = (((freq + .0) / size) * 100);
                fnl.add(freque);
                name.add(a);
                freqtot += freque;
                jTable1.getModel().setValueAt(a, ct, 0);
                jTable1.getModel().setValueAt(String.format("%1.1f", freque) + "%", ct, 1);
                ct++;
                freq = 0;

                check.add(a);
            }
            total.setText("Total :" + String.format("%1.1f", freqtot));
        }

        if (Chart.isSelected() == true) {
            DefaultPieDataset chart = new DefaultPieDataset();

            int h = 0;
            for (Double z : fnl) {
                chart.setValue(name.get(h) + "", new Double(z));
                h++;
            }
            JFreeChart mychart = ChartFactory.createPieChart3D(Desc.getText() + "", chart, true, true, true);
            PiePlot3D p = (PiePlot3D) mychart.getPlot();
            ChartFrame charteuFrame = new ChartFrame(Desc.getText(), mychart);
            charteuFrame.setVisible(true);
            charteuFrame.setSize(450, 500);
        }

    } else if (Numerical.isSelected() == true && Categorical.isSelected() == false) {
        double subtrahend = 0.5;

        for (int i = 0; i < jTable1.getRowCount();) {
            double d = Double.parseDouble((String) jTable1.getModel().getValueAt(i, 0));
            frame2.add(d);
            i++;
        }
        double max = 0;
        double min = frame2.get(0);
        for (int j = 0; j < frame2.size(); j++) {
            System.out.print("Sulod");
            if (max < frame2.get(j)) {
                max = frame2.get(j);
            }
            if (min > frame2.get(j)) {
                min = frame2.get(j);
            }
        }

        System.out.print(frame2);
        double range = max - min;
        double k = Math.ceil(1 + 3.322 * Math.log10(frame2.size()));
        int width = (int) Math.ceil(range / k);

        System.out.println("char:   " + max + " " + min + " " + range + " " + k + " width: " + width);
        double limit = min;
        while (limit < max) {
            limitLeft.add(limit);
            limit += width;
        }

        for (int j = 0; j < limitLeft.size(); j++) {
            System.out.print(limitLeft.get(j) + " ");
        }

        double limit2 = min + width - 1;
        while (limit2 <= max) {
            limitRight.add(limit2);
            limit2 += width;
        }

        if (limitRight.get(limitRight.size() - 1) != max) {
            limitRight.add(max);
        }

        System.out.println();
        for (int j = 0; j < limitRight.size(); j++) {
            System.out.print(limitRight.get(j) + " ");
        }

        //true limit
        if (((String) choice.getSelectedItem()).equals("Integer")) {

            for (int j = 0; j < limitLeft.size(); j++) {
                trueLimitLeft.add(limitLeft.get(j) - 0.5);
            }

            System.out.println();
            for (int j = 0; j < trueLimitLeft.size(); j++) {
                System.out.print(trueLimitLeft.get(j) + " ");
            }

            for (int j = 0; j < limitRight.size(); j++) {
                trueLimitRight.add(limitRight.get(j) + 0.5);
            }

            System.out.println();
            for (int j = 0; j < trueLimitRight.size(); j++) {
                System.out.print(trueLimitRight.get(j) + " ");
            }

        } else if (((String) choice.getSelectedItem()).equals("Floating")) {

            int count1 = 0;
            float diff = 0;
            boolean flag = false;

            for (int j = 0; j < frame2.size(); j++) {
                double value = Math.floor(frame2.get(j));
                //                    System.out.println(frame.get(j));
                diff = (float) (frame2.get(j) - value);
                System.out.println("diff: " + diff);
                String counts = String.valueOf(diff);
                if (diff > 0.0) {
                    if (counts.length() - 1 > count1) {
                        count1 = counts.length() - 1;
                        System.out.println(count1);
                    }
                }
            }

            System.out.println(count1);

            for (int j = 0; j < count1 - 1; j++) {
                subtrahend /= 10;
                System.out.println(subtrahend);
            }

            System.out.println("sub: " + subtrahend);
            for (int j = 0; j < limitLeft.size(); j++) {
                trueLimitLeft.add(limitLeft.get(j) - subtrahend);
            }

            for (int j = 0; j < limitRight.size(); j++) {
                trueLimitRight.add(limitRight.get(j) + subtrahend);
            }
        }
        //midpoint
        for (int j = 0; j < limitLeft.size(); j++) {
            midpoint.add((limitLeft.get(j) + limitRight.get(j)) / 2);
        }

        System.out.println();
        for (int j = 0; j < midpoint.size(); j++) {
            System.out.print(midpoint.get(j) + " ");
        }

        //frequency
        for (int j = 0; j < limitLeft.size(); j++) {
            int count = 0;
            for (int m = 0; m < frame2.size(); m++) {
                if (frame2.get(m) >= limitLeft.get(j) && frame2.get(m) <= limitRight.get(j)) {
                    count++;
                }
            }
            frequency.add(count);
        }

        System.out.println();
        for (int j = 0; j < frequency.size(); j++) {
            System.out.print(frequency.get(j) + " ");
        }

        //percent
        for (int j = 0; j < frequency.size(); j++) {
            double pp = (((double) frequency.get(j) / frame2.size()) * 100);
            percent.add(pp);
        }

        System.out.println();
        for (int j = 0; j < percent.size(); j++) {
            System.out.print(percent.get(j) + " ");
        }

        int cff = 0;
        for (int j = 0; j < frequency.size(); j++) {
            cff += frequency.get(j);
            cf.add(cff);
        }

        System.out.println();
        for (int j = 0; j < cf.size(); j++) {
            System.out.print(cf.get(j) + " ");
        }

        double cpp = 0;
        for (int j = 0; j < percent.size(); j++) {
            cpp += percent.get(j);
            cp.add(cpp);
        }

        System.out.println();

        for (int j = 0; j < cp.size(); j++) {
            System.out.print(cp.get(j) + " ");
        }

        DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
        dtm.setRowCount(limitLeft.size());

        int ct = 0;
        if (collapse.isSelected() == true) {
            for (int j = 0; j < limitLeft.size(); j++) {
                if (ct == 0) {
                    jTable1.getModel().setValueAt("< " + limitRight.get(j), ct, 1);
                    jTable1.getModel().setValueAt("-", ct, 3);
                    name.add("<");
                } else if (ct == limitLeft.size() - 1) {
                    jTable1.getModel().setValueAt("> " + limitLeft.get(j), ct, 1);
                    jTable1.getModel().setValueAt("-", ct, 3);
                    name.add(">");
                } else {
                    jTable1.getModel().setValueAt(limitLeft.get(j) + "-" + limitRight.get(j), ct, 1);
                    jTable1.getModel().setValueAt(midpoint.get(j), ct, 3);
                    name.add(midpoint.get(j) + "");
                }
                jTable1.getModel().setValueAt(trueLimitLeft.get(j) + "-" + trueLimitRight.get(j), ct, 2);
                jTable1.getModel().setValueAt(frequency.get(j), ct, 4);
                jTable1.getModel().setValueAt(percent.get(j), ct, 5);
                jTable1.getModel().setValueAt(cf.get(j), ct, 6);
                jTable1.getModel().setValueAt(cp.get(j), ct, 7);
                ct++;
            }

        } else {
            for (int j = 0; j < limitLeft.size(); j++) {

                jTable1.getModel().setValueAt(limitLeft.get(j) + "-" + limitRight.get(j), ct, 1);
                jTable1.getModel().setValueAt(trueLimitLeft.get(j) + "-" + trueLimitRight.get(j), ct, 2);
                jTable1.getModel().setValueAt(midpoint.get(j), ct, 3);
                name.add(midpoint.get(j) + "");
                jTable1.getModel().setValueAt(frequency.get(j), ct, 4);
                jTable1.getModel().setValueAt(percent.get(j), ct, 5);
                jTable1.getModel().setValueAt(cf.get(j), ct, 6);
                jTable1.getModel().setValueAt(cp.get(j), ct, 7);
                ct++;
            }
        }
        if (Chart.isSelected() == true) {
            DefaultCategoryDataset chart = new DefaultCategoryDataset();

            int h = 0;
            for (Integer z : frequency) {
                chart.setValue(z, "Frequency", name.get(h));
                h++;
            }
            JFreeChart mychart = ChartFactory.createBarChart(Desc.getText() + "", "Midpoint", "Frequency",
                    chart, PlotOrientation.VERTICAL, true, false, false);
            CategoryPlot p = (CategoryPlot) mychart.getPlot();
            p.setDomainGridlinesVisible(true);
            p.getDomainAxis().setCategoryMargin(0.0);
            ChartFrame charteuFrame = new ChartFrame(Desc.getText(), mychart);
            charteuFrame.setVisible(true);
            charteuFrame.setSize(450, 500);
        }
    }
}

From source file:savant.snp.SNPFinderPlugin.java

/**
 * Call SNP for piles for current sequence.
 *//*from  w ww.j a v a 2s .  com*/
private List<Pileup> callSNPsFromPileups(List<Pileup> piles, byte[] sequence) {

    //addMessage("Calling SNPs");

    List<Pileup> snps = new ArrayList<Pileup>();

    int length = sequence.length;
    Pileup.Nucleotide n;
    Pileup p;
    for (int i = 0; i < length; i++) {
        n = Pileup.getNucleotide(sequence[i]);
        p = piles.get(i);
        //System.out.println ("I am here");
        if (p.getSNPNucleotide(snpPrior) != null) {
            //  System.out.println ("I am inside");
            double snpConfidence = -10 * Math.log10(1 - p.getSNPNucleotideConfidence(snpPrior));
            double z = this.confidence; //-Math.log(1 - ((double)this.confidence)/50.0);

            // criteria for calling snps
            if (snpConfidence > z) {
                snps.add(p);
            }
            LOG.debug("conf " + p.getSNPNucleotideConfidence(snpPrior) + "logconf " + snpConfidence + " sens "
                    + z);
        }
    }

    addMessage(snps.size() + " SNPs found");

    return snps;
}

From source file:de.uni_erlangen.lstm.models.adm1.DAEModel.java

@Override
public void computeDerivatives(double t, double[] x, double[] dx)
        throws MaxCountExceededException, DimensionMismatchException {
    for (int i = 0; i < x.length; i++) {
        if (x[i] < 0) {
            xtemp[i] = 0.0;//from  w  ww. j  a va2s.  c  om
        } else {
            xtemp[i] = x[i];
        }
    }

    // Adjustments for acid-base equations
    factor = (1.0 / (param[0]) - 1.0 / (273.15 + xtemp[36])) / (100.0 * R);
    K_w = Math.pow(10, -param[2]) * Math.exp(55900.0 * factor); // T adjustment for K_w 
    K_a_co2 = Math.pow(10, -param[7]) * Math.exp(7646.0 * factor); // T adjustment for K_a_co2 
    K_a_IN = Math.pow(10, -param[8]) * Math.exp(51965.0 * factor); // T adjustment for K_a_IN       
    K_H_h2 = param[9] * Math.exp(-4180.0 * factor); // T adjustment for K_H_h2
    K_H_ch4 = param[10] * Math.exp(-14240.0 * factor); // T adjustment for K_H_ch4
    K_H_co2 = param[11] * Math.exp(-19410.0 * factor); // T adjustment for K_H_co2
    p_gas_h2o = param[12] * Math.exp(5290.0 * (1.0 / (param[0]) - 1.0 / (273.15 + xtemp[36]))); // T adjustment for water vapour saturation pressure   

    K_a_va = Math.pow(10, -param[3]);
    K_a_bu = Math.pow(10, -param[4]);
    K_a_pro = Math.pow(10, -param[5]);
    K_a_ac = Math.pow(10, -param[6]);

    if (fix_pH >= 0) {
        // S_H_ion based on set pH
        shDAE = false;
        S_H_ion = Math.pow(10, -fix_pH);

        // Run the DAE functions
        runDAE();
    } else {
        // Run the DAE functions
        runDAE();

        // SH+ Equation (pH and ion states)
        if (!shDAE) {
            // Scat+(S_IN-Snh3)-hco3-(Sac/64)-(Spro/112)-(Sbu/160)-(Sva/208)-San
            phi = xtemp[24] + (xtemp[10] - xtemp[31]) - xtemp[30] - (xtemp[29] / 64.0) - (xtemp[28] / 112.0)
                    - (xtemp[27] / 160.0) - (xtemp[26] / 208.0) - xtemp[25];
            S_H_ion = (-phi * 0.5) + 0.5 * Math.sqrt(phi * phi + (4.0 * K_w)); // SH+
        }
    }

    // Adjustments for gas pressure
    p_gas_h2 = xtemp[32] * R * (273.15 + xtemp[36]) / 16.0;
    p_gas_ch4 = xtemp[33] * R * (273.15 + xtemp[36]) / 64.0;
    p_gas_co2 = xtemp[34] * R * (273.15 + xtemp[36]);
    P_gas = p_gas_h2 + p_gas_ch4 + p_gas_co2 + p_gas_h2o;

    // pH Inhibition
    I_pH_aa = Math.pow(pHLim_aa, n_aa) / (Math.pow(S_H_ion, n_aa) + Math.pow(pHLim_aa, n_aa));
    I_pH_ac = Math.pow(pHLim_ac, n_ac) / (Math.pow(S_H_ion, n_ac) + Math.pow(pHLim_ac, n_ac));
    I_pH_h2 = Math.pow(pHLim_h2, n_h2) / (Math.pow(S_H_ion, n_h2) + Math.pow(pHLim_h2, n_h2));

    I_IN_lim = 1.0 / (1.0 + param[19] / xtemp[10]); // 1.0/(1.0+K_S_IN/S_IN)
    I_h2_fa = 1.0 / (1.0 + xtemp[7] / param[20]); // 1.0/(1.0+S_h2/K_Ih2_fa)
    I_h2_c4 = 1.0 / (1.0 + xtemp[7] / param[21]); // 1.0/(1.0+S_h2/K_Ih2_c4)
    I_h2_pro = 1.0 / (1.0 + xtemp[7] / param[22]); // 1.0/(1.0+S_h2/K_Ih2_pro)
    I_nh3 = 1.0 / (1.0 + xtemp[31] / param[23]); // 1.0/(1.0+S_nh3/K_I_nh3)

    // Inhibitors
    inhib[0] = I_pH_aa * I_IN_lim; // Inhibition Equation 5 & 6
    inhib[1] = inhib[0] * I_h2_fa; // Inhibition Equation 7
    inhib[2] = inhib[0] * I_h2_c4; // Inhibition Equation 8 & 9
    inhib[3] = inhib[0] * I_h2_pro; // Inhibition Equation 10
    inhib[4] = I_pH_ac * I_IN_lim * I_nh3; // Inhibition Equation 11
    inhib[5] = I_pH_h2 * I_IN_lim; // Inhibition Equation 12   

    // Biochemical process rates
    proc1 = param[24] * xtemp[12]; // k_dis*X_xc, Disintegration
    proc2 = param[25] * xtemp[13]; // k_hyd_ch*X_ch, Hydrolysis of carbohydrates
    proc3 = param[26] * xtemp[14]; // k_hyd_pr*X_pr, Hydrolysis of proteins
    proc4 = param[27] * xtemp[15]; // k_hyd_li*X_li, Hydrolysis of lipids
    proc5 = param[28] * xtemp[0] / (param[29] + xtemp[0]) * xtemp[16] * inhib[0]; // k_m_su*(S_su/(K_S_su+S_su))*X_su*inhib_5, Uptake of sugars
    proc6 = param[30] * xtemp[1] / (param[31] + xtemp[1]) * xtemp[17] * inhib[0]; // k_m_aa*(S_aa/(K_S_aa+S_aa))*X_aa*inhib_6, Uptake of amino acids
    proc7 = param[32] * xtemp[2] / (param[33] + xtemp[2]) * xtemp[18] * inhib[1]; // k_m_fa*(S_fa/(K_S_fa+S_fa))*X_aa*inhib_7, Uptake of LCFA
    proc8 = param[34] * xtemp[3] / (param[35] + xtemp[3]) * xtemp[19] * xtemp[3] / (xtemp[3] + xtemp[4] + eps)
            * inhib[2]; // k_m_c4*(S_va/(K_S_c4+S_va))*X_c4*(S_va/(S_bu+S_va+eps))*inhib_8, Uptake of valerate
    proc9 = param[34] * xtemp[4] / (param[35] + xtemp[4]) * xtemp[19] * xtemp[4] / (xtemp[3] + xtemp[4] + eps)
            * inhib[2]; // k_m_c4*(S_bu/(K_S_c4+S_bu))*X_c4*(S_bu/(S_va+S_bu+eps))*inhib_9, Uptake of butyrate
    proc10 = param[36] * xtemp[5] / (param[37] + xtemp[5]) * xtemp[20] * inhib[3]; // k_m_pro*(S_pro/(K_S_pro+S_pro))*X_pro*inhib_10, Uptake of propionate
    proc11 = param[38] * xtemp[6] / (param[39] + xtemp[6]) * xtemp[21] * inhib[4]; // k_m_ac*(S_ac/(K_S_ac+S_ac))*X_ac*inhib_11, Uptake of acetate
    proc12 = param[40] * xtemp[7] / (param[41] + xtemp[7]) * xtemp[22] * inhib[5]; // k_m_h2*(S_h2/(K_S_h2+S_h2))*X_h2*inhib_12, Uptake of hydrogen
    proc13 = param[42] * xtemp[16]; // k_dec_Xsu*X_su, Decay of X_su
    proc14 = param[43] * xtemp[17]; // k_dec_Xaa*X_aa, Decay of X_aa
    proc15 = param[44] * xtemp[18]; // k_dec_Xfa*X_fa, Decay of X_fa
    proc16 = param[45] * xtemp[19]; // k_dec_Xc4*X_c4, Decay of X_c4
    proc17 = param[46] * xtemp[20]; // k_dec_Xpro*X_pro, Decay of X_pro
    proc18 = param[47] * xtemp[21]; // k_dec_Xac*X_ac, Decay of X_ac
    proc19 = param[48] * xtemp[22]; // k_dec_Xh2*X_h2, Decay of X_h2

    // Gas transfer rates
    procT8 = param[55] * (xtemp[7] - 16.0 * K_H_h2 * p_gas_h2); // kLa*(S_h2-16.0*K_H_h2*p_gas_h2)
    procT9 = param[55] * (xtemp[8] - 64.0 * K_H_ch4 * p_gas_ch4); // kLa*(S_ch4-64.0*K_H_ch4*p_gas_ch4)
    procT10 = param[55] * ((xtemp[9] - xtemp[30]) - K_H_co2 * p_gas_co2); // kLa*((S_IC-S_hco3)-K_H_co2*p_gas_co2)

    // Reactions
    // reac1 = proc2+(1.0-f_fa_li)*proc4-proc5;
    reac1 = proc2 + (1.0 - param[69]) * proc4 - proc5;
    reac2 = proc3 - proc6;
    // reac3 = f_fa_li*proc4-proc7;
    reac3 = param[69] * proc4 - proc7;
    // reac4 = (1.0-Y_aa)*f_va_aa*proc6-proc8;
    reac4 = (1.0 - param[79]) * param[80] * proc6 - proc8;
    //reac5 = (1.0-Y_su)*f_bu_su*proc5+(1.0-Y_aa)*f_bu_aa*proc6-proc9;
    reac5 = (1.0 - param[71]) * param[72] * proc5 + (1.0 - param[79]) * param[82] * proc6 - proc9;
    // reac6 = (1.0-Y_su)*f_pro_su*proc5+(1.0-Y_aa)*f_pro_aa*proc6+(1.0-Y_c4)*0.54*proc8-proc10;
    reac6 = (1.0 - param[71]) * param[74] * proc5 + (1.0 - param[79]) * param[83] * proc6
            + (1.0 - param[86]) * 0.54 * proc8 - proc10;
    // reac7 = (1.0-Y_su)*f_ac_su*proc5+(1.0-Y_aa)*f_ac_aa*proc6+(1.0-Y_fa)*0.7*proc7+(1.0-Y_c4)*0.31*proc8+(1.0-Y_c4)*0.8*proc9+(1.0-Y_pro)*0.57*proc10-proc11;
    reac7 = (1.0 - param[71]) * param[76] * proc5 + (1.0 - param[79]) * param[84] * proc6
            + (1.0 - param[85]) * 0.7 * proc7 + (1.0 - param[86]) * 0.31 * proc8
            + (1.0 - param[86]) * 0.8 * proc9 + (1.0 - param[87]) * 0.57 * proc10 - proc11;
    // reac8 = (1.0-Y_su)*f_h2_su*proc5+(1.0-Y_aa)*f_h2_aa*proc6+(1.0-Y_fa)*0.3*proc7+(1.0-Y_c4)*0.15*proc8+(1.0-Y_c4)*0.2*proc9+(1.0-Y_pro)*0.43*proc10-proc12-procT8;
    reac8 = (1.0 - param[71]) * param[91] * proc5 + (1.0 - param[79]) * param[92] * proc6
            + (1.0 - param[85]) * 0.3 * proc7 + (1.0 - param[86]) * 0.15 * proc8
            + (1.0 - param[86]) * 0.2 * proc9 + (1.0 - param[87]) * 0.43 * proc10 - proc12 - procT8;
    // reac9 = (1.0-Y_ac)*proc11+(1.0-Y_h2)*proc12-procT9;
    reac9 = (1.0 - param[88]) * proc11 + (1.0 - param[90]) * proc12 - procT9;
    reac10 = -stoich1 * proc1 - stoich2 * proc2 - stoich3 * proc3 - stoich4 * proc4 - stoich5 * proc5
            - stoich6 * proc6 - stoich7 * proc7 - stoich8 * proc8 - stoich9 * proc9 - stoich10 * proc10
            - stoich11 * proc11 - stoich12 * proc12 - stoich13 * proc13 - stoich13 * proc14 - stoich13 * proc15
            - stoich13 * proc16 - stoich13 * proc17 - stoich13 * proc18 - stoich13 * proc19 - procT10;
    // reac11 = (N_xc-f_xI_xc*N_I-f_sI_xc*N_I-f_pr_xc*N_aa)*proc1-Y_su*N_bac*proc5+(N_aa-Y_aa*N_bac)*proc6-Y_fa*N_bac*proc7-Y_c4*N_bac*proc8-Y_c4*N_bac*proc9-Y_pro*N_bac*proc10-Y_ac*N_bac*proc11-Y_h2*N_bac*proc12+(N_bac-N_xc)*(proc13+proc14+proc15+proc16+proc17+proc18+proc19);
    reac11 = -(param[93] - param[65] * param[94] - param[57] * param[94] - param[61] * param[95]) * proc1
            - param[71] * param[96] * proc5 + (param[95] - param[79] * param[96]) * proc6
            - param[85] * param[96] * proc7 - param[86] * param[96] * proc8 - param[86] * param[96] * proc9
            - param[87] * param[96] * proc10 - param[88] * param[96] * proc11 - param[90] * param[96] * proc12
            + (param[96] - param[93]) * (proc13 + proc14 + proc15 + proc16 + proc17 + proc18 + proc19);
    // reac12 = f_sI_xc*proc1;
    reac12 = param[57] * proc1;
    reac13 = -proc1 + proc13 + proc14 + proc15 + proc16 + proc17 + proc18 + proc19;
    // reac14 = f_ch_xc*proc1-proc2;
    reac14 = param[59] * proc1 - proc2;
    // reac15 = f_pr_xc*proc1-proc3;
    reac15 = param[61] * proc1 - proc3;
    // reac16 = f_li_xc*proc1-proc4;
    reac16 = param[63] * proc1 - proc4;
    // reac17 = Y_su*proc5-proc13;
    reac17 = param[71] * proc5 - proc13;
    // reac18 = Y_aa*proc6-proc14;
    reac18 = param[79] * proc6 - proc14;
    // reac19 = Y_fa*proc7-proc15;
    reac19 = param[85] * proc7 - proc15;
    // reac20 = Y_c4*proc8+Y_c4*proc9-proc16;
    reac20 = param[86] * proc8 + param[86] * proc9 - proc16;
    // reac21 = Y_pro*proc10-proc17;
    reac21 = param[87] * proc10 - proc17;
    // reac22 = Y_ac*proc11-proc18;
    reac22 = param[88] * proc11 - proc18;
    // reac23 = Y_h2*proc12-proc19;
    reac23 = param[90] * proc12 - proc19;
    // reac24 = f_xI_xc*proc1;
    reac24 = param[65] * proc1;

    q_gas = param[97] * (P_gas - P_atm);
    if (q_gas < 0)
        q_gas = 0.0;

    // DE's -> Soluble matter
    // dSsu/dt = Qad/Vad,liq(Ssu,i-Ssu)+reac1
    dx[0] = (xtemp[35] / param[98]) * (u[0] - xtemp[0]) + reac1; // Ssu
    dx[1] = (xtemp[35] / param[98]) * (u[1] - xtemp[1]) + reac2; // Saa
    dx[2] = (xtemp[35] / param[98]) * (u[2] - xtemp[2]) + reac3; // Sfa
    dx[3] = (xtemp[35] / param[98]) * (u[3] - xtemp[3]) + reac4; // Sva
    dx[4] = (xtemp[35] / param[98]) * (u[4] - xtemp[4]) + reac5; // Sbu
    dx[5] = (xtemp[35] / param[98]) * (u[5] - xtemp[5]) + reac6; // Spro
    dx[6] = (xtemp[35] / param[98]) * (u[6] - xtemp[6]) + reac7; // Sac

    if (!sh2DAE) {
        dx[7] = (xtemp[35] / param[98]) * (u[7] - xtemp[7]) + reac8; // Sh2
    }

    dx[8] = (xtemp[35] / param[98]) * (u[8] - xtemp[8]) + reac9; // Sch4
    dx[9] = (xtemp[35] / param[98]) * (u[9] - xtemp[9]) + reac10; // SIC
    dx[10] = (xtemp[35] / param[98]) * (u[10] - xtemp[10]) + reac11; // SIN
    dx[11] = (xtemp[35] / param[98]) * (u[11] - xtemp[11]) + reac12; // SI

    // DE's -> Particulate matter
    dx[12] = (xtemp[35] / param[98]) * (u[12] - xtemp[12]) + reac13; // Xc
    dx[13] = (xtemp[35] / param[98]) * (u[13] - xtemp[13]) + reac14; // Xch
    dx[14] = (xtemp[35] / param[98]) * (u[14] - xtemp[14]) + reac15; // Xpr
    dx[15] = (xtemp[35] / param[98]) * (u[15] - xtemp[15]) + reac16; // Xli
    dx[16] = (xtemp[35] / param[98]) * (u[16] - xtemp[16]) + reac17; // Xsu
    dx[17] = (xtemp[35] / param[98]) * (u[17] - xtemp[17]) + reac18; // Xaa
    dx[18] = (xtemp[35] / param[98]) * (u[18] - xtemp[18]) + reac19; // Xfa
    dx[19] = (xtemp[35] / param[98]) * (u[19] - xtemp[19]) + reac20; // Xc4
    dx[20] = (xtemp[35] / param[98]) * (u[20] - xtemp[20]) + reac21; // Xpro
    dx[21] = (xtemp[35] / param[98]) * (u[21] - xtemp[21]) + reac22; // Xac
    dx[22] = (xtemp[35] / param[98]) * (u[22] - xtemp[22]) + reac23; // Xh2
    dx[23] = (xtemp[35] / param[98]) * (u[23] - xtemp[23]) + reac24; // XI

    dx[24] = (xtemp[35] / param[98]) * (u[24] - xtemp[24]); // Scat+
    dx[25] = (xtemp[35] / param[98]) * (u[25] - xtemp[25]); // San-

    // Acid-base process rates for ODE
    //k_A_Bva*(S_hva*(K_A_va+S_H_ion)-K_a_va*S_va)
    if (!shDAE && fix_pH < 0) {
        dx[26] = -(param[49] * (xtemp[26] * (K_a_va + S_H_ion) - K_a_va * xtemp[3])); // Sva-
        dx[27] = -(param[50] * (xtemp[27] * (K_a_bu + S_H_ion) - K_a_bu * xtemp[4])); // Sbu-
        dx[28] = -(param[51] * (xtemp[28] * (K_a_pro + S_H_ion) - K_a_pro * xtemp[5])); // Spro-
        dx[29] = -(param[52] * (xtemp[29] * (K_a_ac + S_H_ion) - K_a_ac * xtemp[6])); // Sac-
        dx[30] = -(param[53] * (xtemp[30] * (K_a_co2 + S_H_ion) - K_a_co2 * xtemp[9])); // SHCO3-
        dx[31] = -(param[54] * (xtemp[31] * (K_a_IN + S_H_ion) - K_a_IN * xtemp[10])); // SNH3   
    }

    dx[32] = -xtemp[32] * q_gas / param[99] + procT8 * param[98] / param[99]; // Sgas,h2
    dx[33] = -xtemp[33] * q_gas / param[99] + procT9 * param[98] / param[99]; // Sgas,ch4
    dx[34] = -xtemp[34] * q_gas / param[99] + procT10 * param[98] / param[99]; // Sgas,co2

    dx[35] = 0; // Flow
    dx[36] = 0; // Temp

    // Correction by factor of 64.0 due to COD basis of Sgas,ch4  // Methane gas (m3/d)
    //xtemp[37] = (q_gas*xtemp[33])*R*(273.15+xtemp[36])/64.0; // Calculate methane production from concentration in gas phase
    xtemp[37] = q_gas * (p_gas_ch4 / P_gas); // Calculate methane production from partial pressures

    xtemp[38] = q_gas;// Gas production (m3/d)

    xtemp[39] = -Math.log10(S_H_ion); // pH

    // SCO2 = SIC - SHCO3
    xtemp[40] = xtemp[9] - xtemp[30]; // SCO2
    // SNH4+ = SIN - SNH3
    xtemp[41] = xtemp[10] - xtemp[31]; // SNH4+
}

From source file:ubic.gemma.core.ontology.GoMetric.java

/**
 * @param  GOFreq hashMap of GO term to its frequency in the corpus
 * @param  N      number of genes in the corpus
 * @return        map/* ww  w .j a va 2 s.c o m*/
 */
private Map<String, Double> createWeightMap(Map<String, Integer> GOFreq, Integer N) {

    Map<String, Double> weightMap = new HashMap<>();
    for (String id : GOFreq.keySet()) {
        Double weightedGO = Math.log10((double) N / GOFreq.get(id));
        weightMap.put(id, weightedGO);
    }
    return weightMap;
}

From source file:org.esa.s1tbx.calibration.gpf.calibrators.ERSCalibrator.java

/**
 * Called by the framework in order to compute a tile for the given target band.
 * <p>The default implementation throws a runtime exception with the message "not implemented".</p>
 *
 * @param targetBand The target band./* www.j a v a  2s  . co m*/
 * @param targetTile The current tile associated with the target band to be computed.
 * @param pm         A progress monitor which should be used to determine computation cancelation requests.
 * @throws OperatorException If an error occurs during computation of the target raster.
 */
@Override
public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm) throws OperatorException {

    try {
        final Rectangle targetTileRectangle = targetTile.getRectangle();

        final int x0 = targetTileRectangle.x;
        final int y0 = targetTileRectangle.y;
        final int w = targetTileRectangle.width;
        final int h = targetTileRectangle.height;
        //System.out.println("x0 = " + x0 + ", y0 = " + y0 + ", w = " + w + ", h = " + h);

        final ProductData trgData = targetTile.getDataBuffer();
        Band sourceBand1 = null;
        Band sourceBand2 = null;
        Tile sourceRaster1 = null;
        Tile sourceRaster2 = null;
        ProductData srcData1 = null;
        ProductData srcData2 = null;

        final String[] srcBandNames = targetBandNameToSourceBandName.get(targetBand.getName());
        if (srcBandNames.length == 1) {
            sourceBand1 = sourceProduct.getBand(srcBandNames[0]);
            sourceRaster1 = getSourceTile(sourceBand1, targetTileRectangle);
            srcData1 = sourceRaster1.getDataBuffer();
        } else {
            sourceBand1 = sourceProduct.getBand(srcBandNames[0]);
            sourceBand2 = sourceProduct.getBand(srcBandNames[1]);
            sourceRaster1 = getSourceTile(sourceBand1, targetTileRectangle);
            sourceRaster2 = getSourceTile(sourceBand2, targetTileRectangle);
            srcData1 = sourceRaster1.getDataBuffer();
            srcData2 = sourceRaster2.getDataBuffer();
        }

        final Unit.UnitType tgtBandUnit = Unit.getUnitType(targetBand);
        final Unit.UnitType srcBandUnit = Unit.getUnitType(sourceBand1);

        // copy band if unit is phase
        if (tgtBandUnit == Unit.UnitType.PHASE) {
            targetTile.setRawSamples(sourceRaster1.getRawSamples());
            return;
        }

        if (applyAntennaPatternCorrection && !isAntPattAvailable) {
            computeAntennaPatternCorrectionFactors(0, sourceImageWidth);
        }

        if (applyADCSaturationCorrection && !adcHasBeenTestedFlag) {
            testADC(sourceBand1, sourceBand2, srcBandUnit);
        }

        boolean applyADCSaturationCorrectionToCurrentTile = false;
        if (applyADCSaturationCorrection && h >= blockHeight && w >= blockWidth) {
            applyADCSaturationCorrectionToCurrentTile = true;
        }

        double[][] adcPowerLoss = null;
        if (applyADCSaturationCorrectionToCurrentTile) {
            adcPowerLoss = computeADCPowerLossValuesForCurrentTile(sourceBand1, sourceBand2, x0, y0, w, h,
                    srcBandUnit);
        }

        final double k = calibrationConstant * FastMath.sin(referenceIncidenceAngle);

        final int maxY = y0 + h;
        final int maxX = x0 + w;

        double sigma, dn, dn2, i, q, phaseTerm = 0.0;
        int index;
        int adcJ = 0;
        for (int x = x0; x < maxX; x++) {

            final double sinIncidenceAngleByK = FastMath.sin(incidenceAngles[x]) / k;
            if (applyADCSaturationCorrectionToCurrentTile) {
                adcJ = Math.min(((x - x0) / blockWidth), adcPowerLoss[0].length - 1);
            }

            for (int y = y0; y < maxY; y++) {
                index = sourceRaster1.getDataBufferIndex(x, y);

                if (srcBandUnit == Unit.UnitType.AMPLITUDE) {
                    dn = srcData1.getElemDoubleAt(index);
                    dn2 = dn * dn;
                } else if (srcBandUnit == Unit.UnitType.INTENSITY) {
                    dn2 = srcData1.getElemDoubleAt(index);
                } else if (srcBandUnit == Unit.UnitType.REAL) {
                    i = srcData1.getElemDoubleAt(index);
                    q = srcData2.getElemDoubleAt(index);
                    dn2 = i * i + q * q;
                    if (tgtBandUnit == Unit.UnitType.REAL) {
                        phaseTerm = i / Math.sqrt(dn2);
                    } else if (tgtBandUnit == Unit.UnitType.IMAGINARY) {
                        phaseTerm = q / Math.sqrt(dn2);
                    }
                } else if (srcBandUnit == Unit.UnitType.INTENSITY_DB) {
                    dn2 = FastMath.pow(10, srcData1.getElemDoubleAt(index) / 10.0); // convert dB to linear scale
                } else {
                    throw new OperatorException("ERS Calibration: unhandled unit");
                }

                double calFactor = sinIncidenceAngleByK;

                if (applyAntennaPatternCorrection) {
                    calFactor *= antennaPatternCorrFactor[x];
                }

                if (applyRangeSpreadingLossCorrection) {
                    calFactor *= rangeSpreadingLoss[x];
                }

                if (applyReplicaPowerCorrection) {
                    calFactor *= replicaPulseVariationsCorrectionFactor;
                }

                if (applyADCSaturationCorrectionToCurrentTile) {
                    final int adcI = Math.min(((y - y0) / blockHeight), adcPowerLoss.length - 1);
                    calFactor *= adcPowerLoss[adcI][adcJ];
                }

                sigma = dn2 * calFactor;

                if (isComplex && outputImageInComplex) {
                    sigma = Math.sqrt(sigma) * phaseTerm;
                }

                if (outputImageScaleInDb) { // convert calibration result to dB
                    if (sigma < underFlowFloat) {
                        sigma = -underFlowFloat;
                    } else {
                        sigma = 10.0 * Math.log10(sigma);
                    }
                }

                trgData.setElemDoubleAt(targetTile.getDataBufferIndex(x, y), sigma);
            }
        }
    } catch (Throwable e) {
        OperatorUtils.catchOperatorException("ERSCalibrator", e);
    }
}

From source file:com.jkoolcloud.jesl.simulator.TNT4JSimulator.java

private static int printProgress(String text, long iteration, int trcWidth) {
    if (numIterations == 1)
        return 0;

    int itPct = (int) ((double) iteration / numIterations * 100.0);
    int maxItWidth = (int) (Math.log10(numIterations) + 1);
    String bkSpStr = StringUtils.leftPad("", trcWidth, '\b');
    String trcMsg = String.format(bkSpStr + "%" + maxItWidth + "d (%02d%%)", iteration, itPct);
    trcWidth = trcMsg.length() - bkSpStr.length();
    System.out.print(trcMsg);//from  w w w .j a v a 2s .  c  o m
    return trcWidth;
}

From source file:it.cnr.isti.hpc.dexter.disambiguation.TurkishEntityDisambiguator.java

@Override
public EntityMatchList disambiguate(DexterLocalParams localParams, SpotMatchList sml) {
    entityScoreMap = new HashMap<String, EntityScores>();
    selectedEntities = new HashSet<String>();
    Multiset<String> entityFrequencyMultiset = HashMultiset.create();

    EntityMatchList entities = sml.getEntities();
    String inputText = localParams.getParams().get("text");
    String algorithm = Property.getInstance().get("algorithm");

    String ambigious = Property.getInstance().get("algorithm.ambigious");

    List<Token> inputTokens = Zemberek.getInstance().disambiguateFindTokens(inputText, false, true);
    List<Double> documentVector = DescriptionEmbeddingAverage.getAverageVectorList(inputText);
    Multiset<String> inputTokensMultiset = HashMultiset.create();
    for (Token token : inputTokens) {
        inputTokensMultiset.add(token.getMorphText());
    }/*  w  w  w . j  a v a 2s.  c  om*/

    Multiset<String> domainMultiset = HashMultiset.create();
    Multiset<String> typeMultiset = HashMultiset.create();
    HashMap<String, Double> entitySimMap = new HashMap<String, Double>();
    // if (printCandidateEntities) {
    // printEntities(entities);
    // }
    HashSet<String> words = new HashSet<String>();
    Multiset<String> leskWords = HashMultiset.create();

    // first pass for finding number of types and domains
    for (int i = 0; i < entities.size(); i++) {
        EntityMatch em = entities.get(i);
        String id = em.getId();
        if (!entityFrequencyMultiset.contains(id)) {
            entityFrequencyMultiset.add(id);
            Entity entity = em.getEntity();
            words.add(entity.getShingle().getText());
            String type = entity.getPage().getType();
            if (type != null && type.length() > 0) {
                typeMultiset.add(type);
            }
            String domain = entity.getPage().getDomain();
            if (domain != null && domain.length() > 0) {
                domainMultiset.add(domain);
            }

            String desc = entity.getPage().getDescription();
            List<Token> tokens = Zemberek.getInstance().disambiguateFindTokens(desc, false, true);
            for (Token token : tokens) {
                leskWords.add(token.getMorphText());
            }

        } else {
            entityFrequencyMultiset.add(id);
        }
    }

    int maxDomainCount = 0;
    for (String domain : Multisets.copyHighestCountFirst(domainMultiset).elementSet()) {
        maxDomainCount = domainMultiset.count(domain);
        break;
    }
    int maxTypeCount = 0;
    for (String type : Multisets.copyHighestCountFirst(typeMultiset).elementSet()) {
        maxTypeCount = typeMultiset.count(type);
        break;
    }

    double maxSuffixScore = 0, maxLeskScore = 0, maxSimpleLeskScore = 0, maxLinkScore = 0,
            maxHashInfoboxScore = 0, maxwordvecDescriptionLocalScore = 0, maxHashDescriptionScore = 0,
            maxPopularityScore = 0, maxWordvectorAverage = 0, maxWordvecLinksScore = 0;
    // second pass compute similarities between entities in a window
    int currentSpotIndex = -1;
    SpotMatch currentSpot = null;
    for (int i = 0; i < entities.size(); i++) {
        EntityMatch em = entities.get(i);
        SpotMatch spot = em.getSpot();
        if (currentSpot == null || spot != currentSpot) {
            currentSpotIndex++;
            currentSpot = spot;
        }

        String id = em.getId();
        Entity entity = entities.get(i).getEntity();
        EntityPage page = entities.get(i).getEntity().getPage();
        String domain = page.getDomain();
        String type = page.getType();
        Shingle shingle = entity.getShingle();

        /* windowing algorithms stars */
        int left = currentSpotIndex - window;
        int right = currentSpotIndex + window;
        if (left < 0) {
            right -= left;
            left = 0;
        }
        if (right > sml.size()) {
            left += (sml.size()) - right;
            right = sml.size();
            if (left < 0) {
                left = 0;
            }
        }

        double linkScore = 0, hashInfoboxScore = 0, wordvecDescriptionLocalScore = 0, hashDescriptionScore = 0,
                wordvecLinksScore = 0;
        for (int j = left; j < right; j++) {
            SpotMatch sm2 = sml.get(j);
            EntityMatchList entities2 = sm2.getEntities();
            for (EntityMatch em2 : entities2) {
                String id2 = em2.getId();
                EntityPage page2 = em2.getEntity().getPage();
                int counter = 0;
                if (!ambigious.equals("true")) {
                    for (EntityMatch entityMatch : entities2) {
                        if (entityMatch.getId().startsWith("w")) {
                            counter++;
                        }
                    }
                }

                if ((ambigious.equals("true") || counter == 1) && em.getSpot() != em2.getSpot()
                        && !id.equals(id2)) {
                    // Link Similarity calculation starts
                    double linkSim = 0;
                    if (id.startsWith("w") && id2.startsWith("w")) {
                        if (entitySimMap.containsKey("link" + id + id2)) {
                            linkSim = entitySimMap.get("link" + id + id2);
                        } else {
                            HashSet<String> set1 = Sets.newHashSet(page.getLinks().split(" "));
                            HashSet<String> set2 = Sets.newHashSet(page2.getLinks().split(" "));
                            linkSim = JaccardCalculator.calculateSimilarity(set1, set2);
                            entitySimMap.put("link" + id + id2, linkSim);
                        }
                        linkScore += linkSim;
                        // Link Similarity calculation ends
                    }
                    // Entity embedding similarity calculation starts
                    double eeSim = 0;
                    if (id.startsWith("w") && id2.startsWith("w")) {
                        if (entitySimMap.containsKey("ee" + id + id2)) {
                            eeSim = entitySimMap.get("ee" + id + id2);
                        } else {
                            eeSim = EntityEmbeddingSimilarity.getInstance().getSimilarity(page, page2);
                            entitySimMap.put("ee" + id + id2, eeSim);
                        }
                        hashInfoboxScore += eeSim;
                    }
                    double w2veclinksSim = 0;
                    if (id.startsWith("w") && id2.startsWith("w")) {
                        if (entitySimMap.containsKey("wl" + id + id2)) {
                            w2veclinksSim = entitySimMap.get("wl" + id + id2);
                        } else {
                            w2veclinksSim = AveragePooling.getInstance().getSimilarity(page.getWord2vec(),
                                    page2.getWord2vec());
                            entitySimMap.put("wl" + id + id2, w2veclinksSim);
                        }
                        wordvecLinksScore += w2veclinksSim;
                    }

                    // Entity embedding similarity calculation ends

                    // Description word2vec similarity calculation
                    // starts
                    double word2vecSim = 0;

                    if (entitySimMap.containsKey("w2v" + id + id2)) {
                        word2vecSim = entitySimMap.get("w2v" + id + id2);
                    } else {
                        word2vecSim = AveragePooling.getInstance().getSimilarity(page2.getDword2vec(),
                                page.getDword2vec());
                        entitySimMap.put("w2v" + id + id2, word2vecSim);
                    }
                    wordvecDescriptionLocalScore += word2vecSim;
                    // Description word2vec similarity calculation ends

                    // Description autoencoder similarity calculation
                    // starts
                    double autoVecSim = 0;

                    if (entitySimMap.containsKey("a2v" + id + id2)) {
                        autoVecSim = entitySimMap.get("a2v" + id + id2);
                    } else {
                        autoVecSim = AveragePooling.getInstance().getSimilarity(page2.getDautoencoder(),
                                page.getDautoencoder());
                        entitySimMap.put("a2v" + id + id2, autoVecSim);
                    }
                    hashDescriptionScore += autoVecSim;
                    // Description autoencoder similarity calculation
                    // ends

                }
            }
        }
        if (linkScore > maxLinkScore) {
            maxLinkScore = linkScore;
        }
        if (hashInfoboxScore > maxHashInfoboxScore) {
            maxHashInfoboxScore = hashInfoboxScore;
        }
        if (wordvecDescriptionLocalScore > maxwordvecDescriptionLocalScore) {
            maxwordvecDescriptionLocalScore = wordvecDescriptionLocalScore;
        }
        if (hashDescriptionScore > maxHashDescriptionScore) {
            maxHashDescriptionScore = hashDescriptionScore;
        }
        if (wordvecLinksScore > maxWordvecLinksScore) {
            maxWordvecLinksScore = wordvecLinksScore;
        }

        /* windowing algorithms ends */

        double domainScore = 0;
        if (domainMultiset.size() > 0 && maxDomainCount > 1 && domainMultiset.count(domain) > 1) {
            domainScore = (double) domainMultiset.count(domain) / maxDomainCount;
        }
        double typeScore = 0;
        if (typeMultiset.size() > 0 && maxTypeCount > 1 && typeMultiset.count(type) > 1) {
            typeScore = (double) typeMultiset.count(type) / maxTypeCount;
        }
        if (typeBlackList.contains(type)) {
            typeScore /= 10;
        }

        double typeContentScore = 0;
        if (type.length() > 0 && StringUtils.containsIgnoreCase(words.toString(), type)) {
            typeContentScore = 1;
        }

        double typeClassifierScore = TypeClassifier.getInstance().predict(page, page.getTitle(), page.getType(),
                entity.getShingle().getSentence());

        double wordvecDescriptionScore = AveragePooling.getInstance().getSimilarity(documentVector,
                page.getDword2vec());
        if (wordvecDescriptionScore > maxWordvectorAverage) {
            maxWordvectorAverage = wordvecDescriptionScore;
        }

        double suffixScore = 0;

        if (type != null && type.length() > 0) {
            Set<String> suffixes = new HashSet<String>();
            String t = entity.getTitle().toLowerCase(new Locale("tr", "TR"));

            for (int x = 0; x < entities.size(); x++) {
                EntityMatch e2 = entities.get(x);
                if (e2.getId().equals(entity.getId())) {
                    suffixes.add(e2.getMention());
                }
            }
            suffixes.remove(t);
            suffixes.remove(entity.getTitle());
            // String inputTextLower = inputText.toLowerCase(new
            // Locale("tr",
            // "TR"));
            // while (inputTextLower.contains(t)) {
            // int start = inputTextLower.indexOf(t);
            // int end = inputTextLower.indexOf(" ", start + t.length());
            // if (end > start) {
            // String suffix = inputTextLower.substring(start, end);
            // // .replaceAll("\\W", "");
            // if (suffix.contains("'")
            // || (Zemberek.getInstance().hasMorph(suffix)
            // && !suffix.equals(t) && suffix.length() > 4)) {
            // suffixes.add(suffix);
            // }
            // inputTextLower = inputTextLower.substring(end);
            // } else {
            // break;
            // }
            // }
            if (suffixes.size() >= minSuffix) {
                for (String suffix : suffixes) {
                    double sim = gd.calculateSimilarity(suffix, type);
                    suffixScore += sim;
                }
            }
        }

        // String entitySuffix = page.getSuffix();
        // String[] inputSuffix = shingle.getSuffix().split(" ");
        // for (int j = 0; j < inputSuffix.length; j++) {
        // if (entitySuffix.contains(inputSuffix[j])) {
        // suffixScore += 0.25f;
        // }
        // }

        if (suffixScore > maxSuffixScore) {
            maxSuffixScore = suffixScore;
        }
        // if (id.equals("w691538")) {
        // LOGGER.info("");
        // }
        double letterCaseScore = 0;
        int lc = page.getLetterCase();
        if (StringUtils.isAllLowerCase(em.getMention()) && lc == 0 && id.startsWith("t")) {
            letterCaseScore = 1;
        } else if (StringUtils.isAllUpperCase(em.getMention()) && lc == 1 && id.startsWith("w")) {
            letterCaseScore = 1;
        } else if (Character.isUpperCase(em.getMention().charAt(0)) && lc == 2 && id.startsWith("w")) {
            letterCaseScore = 1;
        } else if (StringUtils.isAllLowerCase(em.getMention()) && id.startsWith("t")) {
            letterCaseScore = 1;
        }

        double nameScore = 1 - LevenshteinDistanceCalculator.calculateDistance(page.getTitle(),
                Zemberek.removeAfterSpostrophe(em.getMention()));

        double popularityScore = page.getRank();
        if (id.startsWith("w")) {
            popularityScore = Math.log10(popularityScore + 1);
            if (popularityScore > maxPopularityScore) {
                maxPopularityScore = popularityScore;
            }
        }

        double leskScore = 0, simpleLeskScore = 0;

        String desc = em.getEntity().getPage().getDescription();
        if (desc != null) {
            List<Token> tokens = Zemberek.getInstance().disambiguateFindTokens(desc, false, true);
            for (Token token : tokens) {
                if (inputTokensMultiset.contains(token.getMorphText())
                        && !TurkishNLP.isStopWord(token.getMorphText())) {
                    simpleLeskScore += inputTokensMultiset.count(token.getMorphText());
                }
                if (leskWords.contains(token.getMorphText()) && !TurkishNLP.isStopWord(token.getMorphText())) {
                    leskScore += leskWords.count(token.getMorphText());
                }

            }
            leskScore /= Math.log(tokens.size() + 1);
            simpleLeskScore /= Math.log(tokens.size() + 1);
            if (leskScore > maxLeskScore) {
                maxLeskScore = leskScore;
            }
            if (simpleLeskScore > maxSimpleLeskScore) {
                maxSimpleLeskScore = simpleLeskScore;
            }

            if (!entityScoreMap.containsKey(id)) {
                EntityScores scores = new EntityScores(em, id, popularityScore, nameScore, letterCaseScore,
                        suffixScore, wordvecDescriptionScore, typeContentScore, typeScore, domainScore,
                        hashDescriptionScore, wordvecDescriptionLocalScore, hashInfoboxScore, linkScore,
                        wordvecLinksScore, leskScore, simpleLeskScore, typeClassifierScore);
                entityScoreMap.put(id, scores);
            } else {
                EntityScores entityScores = entityScoreMap.get(id);
                entityScores.setHashInfoboxScore((entityScores.getHashInfoboxScore() + hashInfoboxScore) / 2);
                entityScores.setHashDescriptionScore(
                        (entityScores.getHashInfoboxScore() + hashDescriptionScore) / 2);
                entityScores.setLinkScore((entityScores.getLinkScore() + linkScore) / 2);
                entityScores.setWordvecDescriptionLocalScore(
                        (entityScores.getWordvecDescriptionLocalScore() + wordvecDescriptionLocalScore) / 2);
                entityScores
                        .setWordvecLinksScore((entityScores.getWordvecLinksScore() + wordvecLinksScore) / 2);
                entityScores.setLeskScore((entityScores.getLeskScore() + leskScore) / 2);

            }

        }
    }
    /* normalization and total score calculation starts */
    Set<String> set = new HashSet<String>();
    for (int i = 0; i < entities.size(); i++) {
        EntityMatch em = entities.get(i);
        String id = em.getId();
        EntityScores entityScores = entityScoreMap.get(id);
        if (set.contains(id)) {
            continue;
        }
        if (id.startsWith("w")) {
            if (maxLinkScore > 0 && entityScores.getLinkScore() > 0) {
                entityScores.setLinkScore(entityScores.getLinkScore() / maxLinkScore);
            }
            if (maxHashInfoboxScore > 0 && entityScores.getHashInfoboxScore() > 0) {
                entityScores.setHashInfoboxScore(entityScores.getHashInfoboxScore() / maxHashInfoboxScore);
            }
            if (maxWordvecLinksScore > 0 && entityScores.getWordvecLinksScore() > 0) {
                entityScores.setWordvecLinksScore(entityScores.getWordvecLinksScore() / maxWordvecLinksScore);
            }
            if (maxPopularityScore > 0 && entityScores.getPopularityScore() > 0) {
                entityScores.setPopularityScore(entityScores.getPopularityScore() / maxPopularityScore);
            }
        }
        if (maxwordvecDescriptionLocalScore > 0 && entityScores.getWordvecDescriptionLocalScore() > 0) {
            entityScores.setWordvecDescriptionLocalScore(
                    entityScores.getWordvecDescriptionLocalScore() / maxwordvecDescriptionLocalScore);
        }
        if (maxHashDescriptionScore > 0 && entityScores.getHashDescriptionScore() > 0) {
            entityScores
                    .setHashDescriptionScore(entityScores.getHashDescriptionScore() / maxHashDescriptionScore);
        }
        if (maxWordvectorAverage > 0 && entityScores.getWordvecDescriptionScore() > 0) {
            entityScores.setWordvecDescriptionScore(
                    entityScores.getWordvecDescriptionScore() / maxWordvectorAverage);
        }
        if (maxLeskScore > 0 && entityScores.getLeskScore() > 0) {
            entityScores.setLeskScore(entityScores.getLeskScore() / maxLeskScore);
        }
        if (maxSimpleLeskScore > 0 && entityScores.getSimpleLeskScore() > 0) {
            entityScores.setSimpleLeskScore(entityScores.getSimpleLeskScore() / maxSimpleLeskScore);
        }
        if (maxSuffixScore > 0 && entityScores.getSuffixScore() > 0) {
            entityScores.setSuffixScore(entityScores.getSuffixScore() / maxSuffixScore);
        }
        set.add(id);
    }

    LOGGER.info("\t"
            + "id\tTitle\tURL\tScore\tPopularity\tName\tLesk\tSimpeLesk\tCase\tNoun\tSuffix\tTypeContent\tType\tDomain\twordvecDescription\twordvecDescriptionLocal\thashDescription\thashInfobox\tword2vecLinks\tLink\t\ttypeClassifier\tDescription");
    for (int i = 0; i < entities.size(); i++) {
        EntityMatch em = entities.get(i);
        String id = em.getId();
        EntityScores e = entityScoreMap.get(id);
        double wikiScore = 0;
        if (id.startsWith("w") && Character.isUpperCase(em.getMention().charAt(0))) {
            wikiScore = wikiWeight;
        } else if (id.startsWith("t") && Character.isLowerCase(em.getMention().charAt(0))) {
            wikiScore = wikiWeight;
        }
        // if(id.equals("w508792")){
        // LOGGER.info("");
        // }
        double totalScore = wikiScore + e.getPopularityScore() * popularityWeight
                + e.getNameScore() * nameWeight + e.getLeskScore() * leskWeight
                + e.getSimpleLeskScore() * simpleLeskWeight + e.getLetterCaseScore() * letterCaseWeight
                + e.getSuffixScore() * suffixWeight + e.getTypeContentScore() * typeContentWeight
                + e.getTypeScore() * typeWeight + e.getDomainScore() * domainWeight
                + e.getWordvecDescriptionScore() * wordvecDescriptionWeight
                + e.getWordvecDescriptionLocalScore() * wordvecDescriptionLocalWeight
                + e.getHashDescriptionScore() * hashDescriptionWeight
                + e.getHashInfoboxScore() * hashInfoboxWeight + e.getWordvecLinksScore() * word2vecLinksWeight
                + e.getLinkScore() * linkWeight + e.getTypeClassifierkScore() * typeClassifierkWeight;
        if (ranklib == true) {
            totalScore = RankLib.getInstance().score(e);
        }

        if (em.getEntity().getPage().getUrlTitle().contains("(")) {
            totalScore /= 2;
        }
        em.setScore(totalScore);
        e.setScore(totalScore);

        LOGGER.info("\t" + id + "\t" + em.getEntity().getPage().getTitle() + "\t"
                + em.getEntity().getPage().getUrlTitle() + "\t" + em.getScore() + "\t"
                + e.getPopularityScore() * popularityWeight + "\t" + e.getNameScore() * nameWeight + "\t"
                + e.getLeskScore() * leskWeight + "\t" + e.getSimpleLeskScore() * simpleLeskWeight + "\t"
                + e.getLetterCaseScore() * letterCaseWeight + "\t" + e.getSuffixScore() * suffixWeight + "\t"
                + e.getTypeContentScore() * typeContentWeight + "\t" + e.getTypeScore() * typeWeight + "\t"
                + e.getDomainScore() * domainWeight + "\t"
                + e.getWordvecDescriptionScore() * wordvecDescriptionWeight + "\t"
                + e.getWordvecDescriptionLocalScore() * wordvecDescriptionLocalWeight + "\t"
                + e.getHashDescriptionScore() * hashDescriptionWeight + "\t"
                + e.getHashInfoboxScore() * hashInfoboxWeight + "\t"
                + e.getWordvecLinksScore() * word2vecLinksWeight + "\t" + e.getLinkScore() * linkWeight + "\t"
                + e.getTypeClassifierkScore() * typeClassifierkWeight + "\t"
                + em.getEntity().getPage().getDescription());
    }

    // if (annotateEntities) {
    // annotateEntities(localParams.getParams().get("originalText"), sml);
    // }

    EntityMatchList eml = new EntityMatchList();
    for (SpotMatch match : sml) {
        EntityMatchList list = match.getEntities();
        if (!list.isEmpty()) {
            list.sort();
            eml.add(list.get(0));
            selectedEntities.add(list.get(0).getId());
        }
    }
    return eml;
}

From source file:asl.util.PlotMaker.java

public void plotSpecAmp(double freq[], double[] amp, double[] phase, String plotString) {

    // plotTitle = "2012074.IU_ANMO.00-BHZ " + plotString
    final String plotTitle = String.format("%04d%03d.%s.%s %s", date.get(Calendar.YEAR),
            date.get(Calendar.DAY_OF_YEAR), station, channel, plotString);
    // plot filename = "2012074.IU_ANMO.00-BHZ" + plotString + ".png"
    final String pngName = String.format("%s/%04d%03d.%s.%s.%s.png", outputDir, date.get(Calendar.YEAR),
            date.get(Calendar.DAY_OF_YEAR), station, channel, plotString);

    File outputFile = new File(pngName);

    // Check that we will be able to output the file without problems and if not --> return
    if (!checkFileOut(outputFile)) {
        System.out.format("== plotSpecAmp: request to output plot=[%s] but we are unable to create it "
                + " --> skip plot\n", pngName);
        return;//from  w  ww . j  a  va  2s  .  c  o m
    }

    final XYSeries series1 = new XYSeries("Amplitude");
    final XYSeries series2 = new XYSeries("Phase");

    double maxdB = 0.;
    for (int k = 0; k < freq.length; k++) {
        double dB = 20. * Math.log10(amp[k]);
        series1.add(freq[k], dB);
        series2.add(freq[k], phase[k]);
        if (dB > maxdB) {
            maxdB = dB;
        }
    }

    //final XYItemRenderer renderer = new StandardXYItemRenderer();
    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    Rectangle rectangle = new Rectangle(3, 3);
    renderer.setSeriesShape(0, rectangle);
    //renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesShapesVisible(0, false);
    renderer.setSeriesLinesVisible(0, true);

    renderer.setSeriesShape(1, rectangle);
    renderer.setSeriesShapesVisible(1, true);
    renderer.setSeriesLinesVisible(1, false);

    Paint[] paints = new Paint[] { Color.red, Color.blue };
    renderer.setSeriesPaint(0, paints[0]);
    //renderer.setSeriesPaint(1, paints[1]);

    final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    renderer2.setSeriesPaint(0, paints[1]);
    renderer2.setSeriesShapesVisible(0, false);
    renderer2.setSeriesLinesVisible(0, true);

    // Stroke is part of Java Swing ...
    //renderer2.setBaseStroke( new Stroke( ... ) );

    double ymax;
    if (maxdB < 10) {
        ymax = 10.;
    } else {
        ymax = maxdB + 2;
        ;
    }

    final NumberAxis verticalAxis = new NumberAxis("Spec Amp (dB)");
    verticalAxis.setRange(new Range(-40, ymax));
    verticalAxis.setTickUnit(new NumberTickUnit(5));

    //final LogarithmicAxis verticalAxis = new LogarithmicAxis("Amplitude Response");
    //verticalAxis.setRange( new Range(0.01 , 10) );

    final LogarithmicAxis horizontalAxis = new LogarithmicAxis("Frequency (Hz)");
    //horizontalAxis.setRange( new Range(0.0001 , 100.5) );
    horizontalAxis.setRange(new Range(0.00009, 110));

    final XYSeriesCollection seriesCollection = new XYSeriesCollection();
    seriesCollection.addSeries(series1);

    final XYPlot xyplot = new XYPlot((XYDataset) seriesCollection, null, verticalAxis, renderer);
    //final XYPlot xyplot = new XYPlot((XYDataset)seriesCollection, horizontalAxis, verticalAxis, renderer);

    xyplot.setDomainGridlinesVisible(true);
    xyplot.setRangeGridlinesVisible(true);
    xyplot.setRangeGridlinePaint(Color.black);
    xyplot.setDomainGridlinePaint(Color.black);

    final NumberAxis phaseAxis = new NumberAxis("Phase (Deg)");
    phaseAxis.setRange(new Range(-180, 180));
    phaseAxis.setTickUnit(new NumberTickUnit(30));
    final XYSeriesCollection seriesCollection2 = new XYSeriesCollection();
    seriesCollection2.addSeries(series2);
    final XYPlot xyplot2 = new XYPlot((XYDataset) seriesCollection2, null, phaseAxis, renderer2);

    //CombinedXYPlot combinedPlot = new CombinedXYPlot( horizontalAxis, CombinedXYPlot.VERTICAL );
    CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis);
    combinedPlot.add(xyplot, 1);
    combinedPlot.add(xyplot2, 1);
    combinedPlot.setGap(15.);

    //final JFreeChart chart = new JFreeChart(xyplot);
    final JFreeChart chart = new JFreeChart(combinedPlot);
    chart.setTitle(new TextTitle(plotTitle));

    // Here we need to see if test dir exists and create it if necessary ...
    try {
        //ChartUtilities.saveChartAsJPEG(new File("chart.jpg"), chart, 500, 300);
        //ChartUtilities.saveChartAsPNG(outputFile, chart, 500, 300);
        ChartUtilities.saveChartAsPNG(outputFile, chart, 1000, 800);
    } catch (IOException e) {
        System.err.println("Problem occurred creating chart.");

    }
}

From source file:ubic.gemma.ontology.GoMetric.java

/**
 * @param GOFreq hashMap of GO term to its frequency in the corpus
 * @param N number of genes in the corpus
 * @return/*  w  ww .ja  v a  2s.co m*/
 */
private Map<String, Double> createWeightMap(Map<String, Integer> GOFreq, Integer N) {

    Map<String, Double> weightMap = new HashMap<String, Double>();
    for (String id : GOFreq.keySet()) {
        Double weightedGO = Math.log10((double) N / GOFreq.get(id));
        weightMap.put(id, weightedGO);
    }
    return weightMap;
}