Package joshua.discriminative.semiring_parsingv2.applications

Examples of joshua.discriminative.semiring_parsingv2.applications.HypLenSquareExpectation


    }

   
    private void reComputeFunctionValueAndGradientHelper(double[] weightsForTheta){
   
     MinRiskDADenseFeaturesSemiringParser gradientSemiringParser
       = new MinRiskDADenseFeaturesSemiringParser(temperature);
      
       
    for(int sentID=0; sentID < numSentence; sentID ++){
      //System.out.println("#Process sentence " + sent_id);
     
      FeatureForest fForest = hgFactory.nextHG(sentID);
     
      fForest.setFeatureWeights(weightsForTheta);
      fForest.setScale(scalingFactor);
 

      /** Based on a model and a test hypergraph (which provides the topology and feature/risk annotation),
       *  compute the gradient.
       **/
     
      //@todo: we should check if hg_test is a feature forest or not
      gradientSemiringParser.setHyperGraph(fForest);
 
      //== compute gradient and function value
      HashMap<Integer, Double> gradients = gradientSemiringParser.computeGradientForTheta();
     
      double gradientForScalingFactor = 0;
      if(shouldComputeGradientForScalingFactor)
        gradientForScalingFactor = computeGradientForScalingFactor(gradients, weightsForTheta, scalingFactor);
     
      double funcVal = gradientSemiringParser.getFuncVal();
      double risk = gradientSemiringParser.getRisk();
      double entropy = gradientSemiringParser.getEntropy();
     
      //== accumulate gradient and function value
      accumulateGradient(gradients, gradientForScalingFactor, weightsForTheta, funcVal, risk, entropy);
     
      
View Full Code Here


    this.shouldComputeGradientForScalingFactor = shouldComputeGradientForScalingFactor;
   
   
    if(useSemiringV2){
      //System.out.println("----------------useSemiringV2");
      this.gradientSemiringParserV2 =  new MinRiskDADenseFeaturesSemiringParser(this.temperature);     
    }else{
      //System.out.println("----------------useSemiringV1");
      this.gradientSemiringParserV1 = new MinRiskDAGradientSemiringParser(1, 0, scalingFactor, temperature);     
        this.funcValSemiringParserV1 =new MinRiskDAFuncValSemiringParser(1, 0, scalingFactor, temperature);     
    }
View Full Code Here

  @Override
  protected ExpectationSemiringPM<LogSemiring, RiskAndEntropyPM, ListPM, ListPM, MinRiskDABO>
 
  createNewXWeight() {   
    ListPM s = new ListPM( new SparseMap() );   
    ListPM t = new ListPM( new SparseMap() );   
    return new ExpectationSemiringPM<LogSemiring, RiskAndEntropyPM, ListPM, ListPM,  MinRiskDABO>( s, t,  pBilinearOperator);
  }
View Full Code Here

        SignedValue.createSignedValueFromRealNumber(rRisk)
    );*/
       
     
    SparseMap gradientsMap = getFeatureForest().getGradientSparseMap(parentItem, dt, logProb);
    ListPM s = new ListPM( gradientsMap );
   
 
    //== t = L_e * (P_e)' - temperature * (1+logP_e) (P_e)' = (P_e)' * ( L_e - temperature * (1+logP_e) )
    //ListPM t = pBilinearOperator.bilinearMulti(r, s);
    ListPM t = pBilinearOperator.bilinearMulti(SignedValue.createSignedValueFromRealNumber(rMixed), s);
   
   
    return new ExpectationSemiringPM<LogSemiring, RiskAndEntropyPM, ListPM, ListPM, MinRiskDABO>(s, t, pBilinearOperator);
  }
View Full Code Here

    SparseMap res = s.getValue().duplicate();
    for(SignedValue signedVal : res.getValues())
      signedVal.multi(r.getValue());   
   
   
    return new ListPM(res);
  }
View Full Code Here

    //== get SparseArray
    SparseMap res = s.getValue().duplicate();
    for(SignedValue signedVal : res.getValues())
      signedVal.multi(r);   
   
    return new ListPM(res);
  }
View Full Code Here

public class ScalarBO implements BilinearOperator<ScalarPM, ScalarPM, ScalarPM>{

  public ScalarPM bilinearMulti(ScalarPM r, ScalarPM s) {
    SignedValue res = SignedValue.multi(r.getValue(), s.getValue() );
    return new ScalarPM(res);
  }
View Full Code Here

    this.scale = scale;
  }
 
  @Override
  protected ScalarPM createNewXWeight() {
    return new ScalarPM();
  }  
View Full Code Here

    double logProb = scale * dt.getTransitionLogP(false);
    LogSemiring p = new LogSemiring(logProb);
   
    double val = logProb;
   
    ScalarPM r =  new ScalarPM( SignedValue.createSignedValueFromRealNumber(val) );
    moduleMultiSemiring(r, p);
   
    return r;
  }
View Full Code Here

 
 
  @Override
  public void normalizeGoal() {
    LogSemiring goalKVal = getGoalK();
    ScalarPM goalX = getGoalX();
   
    //goalKVal.printInfor();
    //goalXVal.printInfor();
   
    double normConstant = goalKVal.getLogValue();//p
    goalX.getValue().multiLogNumber(-normConstant);//r
   
  }
View Full Code Here

TOP

Related Classes of joshua.discriminative.semiring_parsingv2.applications.HypLenSquareExpectation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.