public virtual double[][] SeparateLopExpertWeights(double[] learnedParams)
 {
     double[][]   learnedWeights   = new double[numLopExpert][];
     double[][][] learnedWeights2D = SeparateLopExpertWeights2D(learnedParams);
     for (int i = 0; i < numLopExpert; i++)
     {
         learnedWeights[i] = CRFLogConditionalObjectiveFunction.To1D(learnedWeights2D[i], lopExpertWeights[i].Length);
     }
     return(learnedWeights);
 }
Exemple #2
0
            public virtual Pair <int, double> Process(Pair <int, IList <int> > threadIDAndDocIndices)
            {
                int tID = threadIDAndDocIndices.First();

                if (tID < 0 || tID >= this._enclosing.multiThreadGrad)
                {
                    throw new ArgumentException("threadID must be with in range 0 <= tID < multiThreadGrad(=" + this._enclosing.multiThreadGrad + ")");
                }
                IList <int> docIDs = threadIDAndDocIndices.Second();

                double[][] partE;
                // initialized below
                double[][] partEhat = null;
                // initialized below
                if (this._enclosing.multiThreadGrad == 1)
                {
                    partE = this._enclosing.E;
                    if (this.calculateEmpirical)
                    {
                        partEhat = this._enclosing.Ehat;
                    }
                }
                else
                {
                    partE = this._enclosing.parallelE[tID];
                    // TODO: if we put this on the heap, this clearing will be unnecessary
                    CRFLogConditionalObjectiveFunction.Clear2D(partE);
                    if (this.calculateEmpirical)
                    {
                        partEhat = this._enclosing.parallelEhat[tID];
                        CRFLogConditionalObjectiveFunction.Clear2D(partEhat);
                    }
                }
                double probSum = 0;

                foreach (int docIndex in docIDs)
                {
                    if (this.calculateEmpirical)
                    {
                        probSum += this._enclosing.ExpectedAndEmpiricalCountsAndValueForADoc(partE, partEhat, docIndex);
                    }
                    else
                    {
                        probSum += this._enclosing.ExpectedCountsAndValueForADoc(partE, docIndex);
                    }
                }
                return(new Pair <int, double>(tID, probSum));
            }
Exemple #3
0
 public ExpectationThreadsafeProcessor(CRFLogConditionalObjectiveFunction _enclosing, bool calculateEmpirical)
 {
     this._enclosing         = _enclosing;
     this.calculateEmpirical = calculateEmpirical;
 }
Exemple #4
0
 public ExpectationThreadsafeProcessor(CRFLogConditionalObjectiveFunction _enclosing)
 {
     this._enclosing = _enclosing;
 }