Exemple #1
0
        /**
         * Calculate the distance between two clusters, forcing them to have the same words in them, and to not be related
         * to each other.
         *
         * @param cluster1 the first cluster
         * @param cluster2 the second cluster
         * @return The intra-cluster distance, or Double.NEGATIVE_INFINITY if the clusters should never be clustered
         *         together.
         */
        protected double intraClusterDistance(Cluster cluster1, Cluster cluster2)
        {
            LogMath logMath = LogMath.getLogMath();
            double  maxSim  = Double.NegativeInfinity;

            foreach (Node node1 in cluster1.getElements())
            {
                foreach (Node node2 in cluster2.getElements())
                {
                    if (!node1.getWord().getSpelling().Equals(
                            node2.getWord().getSpelling()))
                    {
                        return(Double.NegativeInfinity);
                    }

                    if (node1.hasAncestralRelationship(node2))
                    {
                        return(Double.NegativeInfinity);
                    }

                    double overlap = getOverlap(node1, node2);
                    if (overlap > 0.0)
                    {
                        overlap  = logMath.logToLinear((float)overlap);
                        overlap += node1.getPosterior() + node2.getPosterior();
                        if (overlap > maxSim)
                        {
                            maxSim = overlap;
                        }
                    }
                }
            }
            return(maxSim);
        }
Exemple #2
0
        /*
         * /// (non-Javadoc)
         *
         * /// @see edu.cmu.sphinx.util.props.Configurable#newProperties(edu.cmu.sphinx.util.props.PropertySheet)
         */
        public override void NewProperties(PropertySheet ps)
        {
            LogMath = LogMath.GetLogMath();

            _acousticModel = (AcousticModel)ps.GetComponent(PropAcousticModel);
            Grammar        = (Grammar)ps.GetComponent(PropGrammar);
            UnitManager    = (UnitManager)ps.GetComponent(PropUnitManager);

            // get the rest of the configuration data
            _logWordInsertionProbability   = LogMath.LinearToLog(ps.GetDouble(PropWordInsertionProbability));
            LogSilenceInsertionProbability = LogMath.LinearToLog(ps.GetDouble(PropSilenceInsertionProbability));
            _logFillerInsertionProbability = LogMath.LinearToLog(ps.GetDouble(PropFillerInsertionProbability));
            _logUnitInsertionProbability   = LogMath.LinearToLog(ps.GetDouble(PropUnitInsertionProbability));
            _languageWeight          = ps.GetFloat(PropLanguageWeight);
            _dumpGStates             = ps.GetBoolean(PropDumpGstates);
            _showCompilationProgress = ps.GetBoolean(PropShowCompilationProgress);
            _spreadWordProbabilitiesAcrossPronunciations = ps.GetBoolean(PropSpreadWordProbabilitiesAcrossPronunciations);

            AddOutOfGrammarBranch = ps.GetBoolean(PropAddOutOfGrammarBranch);

            if (AddOutOfGrammarBranch)
            {
                LogOutOfGrammarBranchProbability = LogMath.LinearToLog(ps.GetDouble(PropOutOfGrammarProbability));
                LogPhoneInsertionProbability     = LogMath.LinearToLog(ps.GetDouble(PropPhoneInsertionProbability));
                PhoneLoopAcousticModel           = (AcousticModel)ps.GetComponent(PropPhoneLoopAcousticModel);
            }

            Name = ps.InstanceName;
        }
        /*
         * (non-Javadoc)
         * We want a very strict grammar structure like the following:
         * InitialNode ----> KW1 ---> KW2 .... ---> KWn ---> FinalNode
         *   ↑________________________________________________|
         */
        protected override GrammarNode createGrammar()
        {
            string silence = Constants.SILENCE_SPELLING;

            initialNode = createGrammarNode(silence);
            finalNode   = createGrammarNode(silence);
            GrammarNode lastNode = createGrammarNode(silence);

            initialNode.add(lastNode, LogMath.getLogOne());
            lastNode.add(initialNode, LogMath.getLogOne());
            GrammarNode lastWordGrammarNode = initialNode;

            /*Iterator<string> iter = tokens.iterator();
             *      while(iter.hasNext()){
             *              GrammarNode currNode = createGrammarNode(iter.next());
             *              lastWordGrammarNode.add(currNode, logMath.getLogOne());
             *              lastWordGrammarNode = currNode;
             *
             *              // Parallel keyword topology
             *              //initialNode.add(currNode, logMath.getLogOne());
             *
             *              //currNode.add(finalNode, logMath.getLogOne());
             *      }*/
            foreach (var token in tokens)
            {
                GrammarNode currNode = createGrammarNode(token);
                lastWordGrammarNode.add(currNode, LogMath.getLogOne());
                lastWordGrammarNode = currNode;
            }
            lastWordGrammarNode.add(lastNode, LogMath.getLogOne());
            lastNode.add(finalNode, logMath.linearToLog(0.0001));
            finalNode.setFinalNode(true);
            return(initialNode);
        }
 public NoSkipGrammar(string text, LogMath logMath, bool showGrammar, bool optimizeGrammar,
                      bool addSilenceWords, bool addFillerWords, Dictionary dictionary) :
     base(showGrammar, optimizeGrammar, addSilenceWords, addFillerWords, dictionary)
 {
     this.logMath = logMath;
     setText(text);
 }
Exemple #5
0
 public SimpleWordListGrammar(String path, Boolean isLooping, Boolean showGrammar, Boolean optimizeGrammar, Boolean addSilenceWords, Boolean addFillerWords, IDictionary dictionary)
     : base(showGrammar, optimizeGrammar, addSilenceWords, addFillerWords, dictionary)
 {
     this._path      = path;
     this._isLooping = isLooping;
     _logMath        = LogMath.GetLogMath();
 }
Exemple #6
0
 internal void logAccumulate(float[] array, float num, LogMath logMath)
 {
     if (!Buffer.assertionsDisabled && this.numerator == null)
     {
         throw new AssertionError();
     }
     if (!Buffer.assertionsDisabled && array == null)
     {
         throw new AssertionError();
     }
     if (!Buffer.assertionsDisabled && this.numerator.Length != array.Length)
     {
         throw new AssertionError();
     }
     if (!Buffer.assertionsDisabled && !this.isLog)
     {
         throw new AssertionError();
     }
     for (int i = 0; i < this.numerator.Length; i++)
     {
         this.numerator[i] = (double)logMath.addAsLinear((float)this.numerator[i], array[i]);
     }
     this.denominator = (double)logMath.addAsLinear((float)this.denominator, num);
     this._wasUsed    = true;
 }
Exemple #7
0
        public FsgModel build_fsg(JsgfRule rule, LogMath logmath, float lw)
        {
            global::System.IntPtr cPtr = sphinxbasePINVOKE.Jsgf_build_fsg(swigCPtr, JsgfRule.getCPtr(rule), LogMath.getCPtr(logmath), lw);
            FsgModel ret = (cPtr == global::System.IntPtr.Zero) ? null : new FsgModel(cPtr, false);

            return(ret);
        }
        public LexTreeLinguist(AcousticModel acousticModel, UnitManager unitManager,
                               LanguageModel languageModel, IDictionary dictionary, Boolean fullWordHistories, Boolean wantUnigramSmear,
                               double wordInsertionProbability, double silenceInsertionProbability, double fillerInsertionProbability,
                               double unitInsertionProbability, float languageWeight, Boolean addFillerWords, Boolean generateUnitStates,
                               float unigramSmearWeight, int maxArcCacheSize)
        {
            _acousticModel = acousticModel;
            _logMath       = LogMath.GetLogMath();
            _unitManager   = unitManager;
            LanguageModel  = languageModel;
            Dictionary     = dictionary;

            //this.fullWordHistories = fullWordHistories;
            _wantUnigramSmear               = wantUnigramSmear;
            _logWordInsertionProbability    = _logMath.LinearToLog(wordInsertionProbability);
            _logSilenceInsertionProbability = _logMath.LinearToLog(silenceInsertionProbability);
            _logFillerInsertionProbability  = _logMath.LinearToLog(fillerInsertionProbability);
            _logUnitInsertionProbability    = _logMath.LinearToLog(unitInsertionProbability);
            LanguageWeight      = languageWeight;
            AddFillerWords      = addFillerWords;
            GenerateUnitStates  = generateUnitStates;
            _unigramSmearWeight = unigramSmearWeight;
            _maxArcCacheSize    = maxArcCacheSize;

            CacheEnabled = maxArcCacheSize > 0;
            if (CacheEnabled)
            {
                ArcCache = new LRUCache <LexTreeState, ISearchStateArc[]>(maxArcCacheSize);
            }
        }
 public override void newProperties(PropertySheet ps)
 {
     base.newProperties(ps);
     this.path      = ps.getString("path");
     this.isLooping = ps.getBoolean("isLooping").booleanValue();
     this.logMath   = LogMath.getLogMath();
 }
Exemple #10
0
        public LogMath GetLogmath()
        {
            global::System.IntPtr cPtr = pocketsphinxPINVOKE.Decoder_GetLogmath(swigCPtr);
            LogMath ret = (cPtr == global::System.IntPtr.Zero) ? null : new LogMath(cPtr, true);

            return(ret);
        }
Exemple #11
0
        public FlatLinguist(AcousticModel acousticModel, Grammar grammar, UnitManager unitManager,
                            double wordInsertionProbability, double silenceInsertionProbability, double fillerInsertionProbability,
                            double unitInsertionProbability, float languageWeight, Boolean dumpGStates, Boolean showCompilationProgress,
                            Boolean spreadWordProbabilitiesAcrossPronunciations, Boolean addOutOfGrammarBranch,
                            double outOfGrammarBranchProbability, double phoneInsertionProbability, AcousticModel phoneLoopAcousticModel)
        {
            _acousticModel = acousticModel;
            LogMath        = LogMath.GetLogMath();
            Grammar        = grammar;
            UnitManager    = unitManager;

            _logWordInsertionProbability   = LogMath.LinearToLog(wordInsertionProbability);
            LogSilenceInsertionProbability = LogMath.LinearToLog(silenceInsertionProbability);
            _logFillerInsertionProbability = LogMath.LinearToLog(fillerInsertionProbability);
            _logUnitInsertionProbability   = LogMath.LinearToLog(unitInsertionProbability);
            _languageWeight = languageWeight;

            _dumpGStates             = dumpGStates;
            _showCompilationProgress = showCompilationProgress;
            _spreadWordProbabilitiesAcrossPronunciations = spreadWordProbabilitiesAcrossPronunciations;

            AddOutOfGrammarBranch = addOutOfGrammarBranch;

            if (addOutOfGrammarBranch)
            {
                LogOutOfGrammarBranchProbability = LogMath.LinearToLog(outOfGrammarBranchProbability);
                LogPhoneInsertionProbability     = LogMath.LinearToLog(phoneInsertionProbability);
                PhoneLoopAcousticModel           = phoneLoopAcousticModel;
            }

            Name = null;
        }
Exemple #12
0
        /**
         * /// Create a MixtureComponent with the given sub components.
         *
         * /// @param mean                         the mean vector for this PDF
         * /// @param meanTransformationMatrix     transformation matrix for this pdf
         * /// @param meanTransformationVector     transform vector for this PDF
         * /// @param variance                     the variance for this PDF
         * /// @param varianceTransformationMatrix var. transform matrix for this PDF
         * /// @param varianceTransformationVector var. transform vector for this PDF
         * /// @param distFloor                    the lowest score value (in linear domain)
         * /// @param varianceFloor                the lowest value for the variance
         */
        public MixtureComponent(
            float[] mean,
            float[][] meanTransformationMatrix,
            float[] meanTransformationVector,
            float[] variance,
            float[][] varianceTransformationMatrix,
            float[] varianceTransformationVector,
            float distFloor,
            float varianceFloor)
        {
            Debug.Assert(variance.Length == mean.Length);

            LogMath = LogMath.GetLogMath();
            Mean    = mean;
            _meanTransformationMatrix = meanTransformationMatrix;
            _meanTransformationVector = meanTransformationVector;
            Variance = variance;
            _varianceTransformationMatrix = varianceTransformationMatrix;
            _varianceTransformationVector = varianceTransformationVector;

            Debug.Assert(distFloor >= 0.0, "distFloot seems to be already in log-domain");
            this.DistFloor = LogMath.LinearToLog(distFloor);
            _varianceFloor = varianceFloor;

            TransformStats();

            LogPreComputedGaussianFactor = PrecomputeDistance();
        }
        /*
         * /// (non-Javadoc)
         *
         * /// @see edu.cmu.sphinx.util.props.Configurable#newProperties(edu.cmu.sphinx.util.props.PropertySheet)
         */
        public override void NewProperties(PropertySheet ps)
        {
            _logMath = LogMath.GetLogMath();

            _acousticModel = (AcousticModel)ps.GetComponent(PropAcousticModel);
            _unitManager   = (UnitManager)ps.GetComponent(PropUnitManager);
            LanguageModel  = (LanguageModel)ps.GetComponent(PropLanguageModel);
            Dictionary     = (IDictionary)ps.GetComponent(PropDictionary);

            //fullWordHistories = ps.getBoolean(PROP_FULL_WORD_HISTORIES);
            _wantUnigramSmear               = ps.GetBoolean(PropWantUnigramSmear);
            _logWordInsertionProbability    = _logMath.LinearToLog(ps.GetDouble(PropWordInsertionProbability));
            _logSilenceInsertionProbability = _logMath.LinearToLog(ps.GetDouble(PropSilenceInsertionProbability));
            _logFillerInsertionProbability  = _logMath.LinearToLog(ps.GetDouble(PropFillerInsertionProbability));
            _logUnitInsertionProbability    = _logMath.LinearToLog(ps.GetDouble(PropUnitInsertionProbability));
            LanguageWeight      = ps.GetFloat(PropLanguageWeight);
            AddFillerWords      = (ps.GetBoolean(PropAddFillerWords));
            GenerateUnitStates  = (ps.GetBoolean(PropGenerateUnitStates));
            _unigramSmearWeight = ps.GetFloat(PropUnigramSmearWeight);
            _maxArcCacheSize    = ps.GetInt(PropCacheSize);

            CacheEnabled = _maxArcCacheSize > 0;
            if (CacheEnabled)
            {
                ArcCache = new LRUCache <LexTreeState, ISearchStateArc[]>(_maxArcCacheSize);
            }
        }
Exemple #14
0
        internal void logNormalizeToSum(LogMath logMath)
        {
            if (!Buffer.assertionsDisabled && !this.isLog)
            {
                throw new AssertionError();
            }
            float minValue = float.MinValue;
            float num      = minValue;

            double[] array = this.numerator;
            int      num2  = array.Length;

            for (int i = 0; i < num2; i++)
            {
                double num3 = array[i];
                if (num3 != (double)minValue)
                {
                    num = logMath.addAsLinear(num, (float)num3);
                }
            }
            for (int j = 0; j < this.numerator.Length; j++)
            {
                if (this.numerator[j] != (double)minValue)
                {
                    double[] array2 = this.numerator;
                    int      num4   = j;
                    double[] array3 = array2;
                    array3[num4] -= (double)num;
                }
            }
            this.denominator = (double)0f;
        }
        public TransitionModel(KaldiTextParser parser)
        {
            parser.expectToken("<TransitionModel>");
            this.parseTopology(parser);
            parser.expectToken("<Triples>");
            this.transitionStates = new HashMap();
            int @int = parser.getInt();
            int num  = 1;

            for (int i = 0; i < @int; i++)
            {
                int    j      = parser.getInt();
                int    int2   = parser.getInt();
                int    int3   = parser.getInt();
                Triple triple = new Triple(j, int2, int3);
                this.transitionStates.put(triple, Integer.valueOf(num));
                num += ((HmmState)((List)this.phoneStates.get(Integer.valueOf(j))).get(int2)).getTransitions().size();
            }
            parser.expectToken("</Triples>");
            parser.expectToken("<LogProbs>");
            this.logProbabilities = parser.getFloatArray();
            parser.expectToken("</LogProbs>");
            parser.expectToken("</TransitionModel>");
            LogMath logMath = LogMath.getLogMath();

            for (int j = 0; j < this.logProbabilities.Length; j++)
            {
                this.logProbabilities[j] = logMath.lnToLog(this.logProbabilities[j]);
            }
        }
Exemple #16
0
 public virtual void newProperties(PropertySheet ps)
 {
     this.logMath    = LogMath.getLogMath();
     this.dataSource = (StreamCepstrumSource)ps.getComponent("source");
     this.frontEnd   = (FrontEnd)ps.getComponent("frontend");
     this.frontEnd.setDataSource(this.dataSource);
 }
Exemple #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GaussianMixture"/> class.
 /// </summary>
 /// <param name="mixtureWeights">The mixture weights for this senone in LogMath log base.</param>
 /// <param name="mixtureComponents">The mixture components for this senone.</param>
 /// <param name="id">The identifier.</param>
 public GaussianMixture(GaussianWeights mixtureWeights, MixtureComponent[] mixtureComponents, int id)
 {
     LogMath            = LogMath.GetLogMath();
     _mixtureComponents = mixtureComponents;
     MixtureWeights     = mixtureWeights;
     _Id = id;
 }
Exemple #18
0
        public AFlatLinguist(AcousticModel acousticModel, Grammar grammar, UnitManager unitManager, double wordInsertionProbability, double silenceInsertionProbability, double unitInsertionProbability, double fillerInsertionProbability, float languageWeight, bool addOutOfGrammarBranch, double outOfGrammarBranchProbability, double phoneInsertionProbability, AcousticModel phoneLoopAcousticModel)
        {
            this.runtime = Runtime.getRuntime();
            this.counterForMemoryLogging = 0L;
            this.EMPTY_ARCS     = new SearchStateArc[0];
            this.successorCache = new HashMap();
            this.logger         = Logger.getLogger(Object.instancehelper_getClass(this).getName());
            this.acousticModel  = acousticModel;
            this.grammar        = grammar;
            this.unitManager    = unitManager;
            LogMath logMath = LogMath.getLogMath();

            this.logWordInsertionProbability    = logMath.linearToLog(wordInsertionProbability);
            this.logSilenceInsertionProbability = logMath.linearToLog(silenceInsertionProbability);
            this.logUnitInsertionProbability    = logMath.linearToLog(unitInsertionProbability);
            this.logFillerInsertionProbability  = logMath.linearToLog(fillerInsertionProbability);
            this.languageWeight                   = languageWeight;
            this.addOutOfGrammarBranch            = addOutOfGrammarBranch;
            this.logOutOfGrammarBranchProbability = logMath.linearToLog(outOfGrammarBranchProbability);
            this.logPhoneInsertionProbability     = logMath.linearToLog((double)this.logPhoneInsertionProbability);
            if (addOutOfGrammarBranch)
            {
                this.phoneLoopAcousticModel = phoneLoopAcousticModel;
            }
        }
Exemple #19
0
 public GaussianMixture(GaussianWeights mixtureWeights, MixtureComponent[] mixtureComponents, int id)
 {
     this.logMath           = LogMath.getLogMath();
     this.mixtureComponents = mixtureComponents;
     this.mixtureWeights    = mixtureWeights;
     this.id = id;
 }
Exemple #20
0
 public GDLDumper(string filename, Linguist linguist, bool verticalLayout, bool skipHMMs, bool dumpArcLabels) : base(filename, linguist)
 {
     this.verticalLayout = verticalLayout;
     this.skipHMMs       = skipHMMs;
     this.dumpArcLabels  = dumpArcLabels;
     this.setDepthFirst(false);
     this.logMath = LogMath.getLogMath();
 }
        public virtual void NewProperties(PropertySheet ps)
        {
            LogMath           = LogMath.GetLogMath();
            AbsoluteBeamWidth = ps.GetInt(PropAbsoluteBeamWidth);
            double relativeBeamWidth = ps.GetDouble(PropRelativeBeamWidth);

            LogRelativeBeamWidth = LogMath.LinearToLog(relativeBeamWidth);
        }
Exemple #22
0
 /// <summary>
 ///Creates a result
 ///@param activeList the active list associated with this result
 ///@param resultList the result list associated with this result
 ///@param frameNumber the frame number for this result.
 ///@param isFinal if true, the result is a final result. This means that the last frame in the
 ///       speech segment has been decoded.
 /// <summary>
 public Result(ActiveList activeList, List <Token> resultList, int frameNumber, Boolean isFinal)
 {
     this.activeList         = activeList;
     this.resultList         = resultList;
     this.currentFrameNumber = frameNumber;
     this._isFinal           = isFinal;
     logMath = LogMath.getLogMath();
 }
Exemple #23
0
 public FSTGrammar(string path, bool showGrammar, bool optimizeGrammar, bool addSilenceWords, bool addFillerWords, dictionary.Dictionary dictionary) : base(showGrammar, optimizeGrammar, addSilenceWords, addFillerWords, dictionary)
 {
     this.ignoreUnknownTransitions = true;
     this.nodes         = new HashMap();
     this.expandedNodes = new HashSet();
     this.logMath       = LogMath.getLogMath();
     this.path          = path;
 }
        public virtual void newProperties(PropertySheet ps)
        {
            this.logMath           = LogMath.getLogMath();
            this.absoluteBeamWidth = ps.getInt("absoluteBeamWidth");
            double linearValue = ps.getDouble("relativeBeamWidth");

            this.logRelativeBeamWidth = this.logMath.linearToLog(linearValue);
        }
        public void newProperties(PropertySheet ps)
        {
            logMath           = LogMath.getLogMath();
            absoluteBeamWidth = ps.getInt(PROP_ABSOLUTE_BEAM_WIDTH);
            double relativeBeamWidth = ps.getDouble(PROP_RELATIVE_BEAM_WIDTH);

            logRelativeBeamWidth = logMath.linearToLog(relativeBeamWidth);
        }
Exemple #26
0
        /*
         * /// (non-Javadoc)
         *
         * /// @see edu.cmu.sphinx.util.props.Configurable#newProperties(edu.cmu.sphinx.util.props.PropertySheet)
         */
        public override void NewProperties(PropertySheet ps)
        {
            base.NewProperties(ps);

            _path      = ps.GetString(PropPath);
            _isLooping = ps.GetBoolean(PropLoop);
            _logMath   = LogMath.GetLogMath();
        }
Exemple #27
0
 public NetworkLanguageModel(string host, int port, URL location, int maxDepth)
 {
     this.host     = host;
     this.port     = port;
     this.maxDepth = maxDepth;
     this.location = location;
     this.logMath  = LogMath.getLogMath();
 }
Exemple #28
0
 public JSGFGrammar(URL baseURL, string grammarName, bool showGrammar, bool optimizeGrammar, bool addSilenceWords, bool addFillerWords, linguist.dictionary.Dictionary dictionary) : base(showGrammar, optimizeGrammar, addSilenceWords, addFillerWords, dictionary)
 {
     this.loadGrammar = true;
     this.logger      = Logger.getLogger(Object.instancehelper_getClass(this).getName());
     this.logMath     = LogMath.getLogMath();
     this.baseURL     = baseURL;
     this.grammarName = grammarName;
     this.loadGrammar = true;
 }
Exemple #29
0
 public override void newProperties(PropertySheet ps)
 {
     base.newProperties(ps);
     this.logger      = ps.getLogger();
     this.logMath     = LogMath.getLogMath();
     this.baseURL     = ConfigurationManagerUtils.getResource("grammarLocation", ps);
     this.grammarName = ps.getString("grammarName");
     this.loadGrammar = true;
 }
Exemple #30
0
 public JSGFGrammar(URL baseUrl, String grammarName, bool showGrammar, bool optimizeGrammar, bool addSilenceWords, bool addFillerWords, IDictionary dictionary)
     : base(showGrammar, optimizeGrammar, addSilenceWords, addFillerWords, dictionary)
 {
     _logMath    = LogMath.GetLogMath();
     BaseUrl     = baseUrl;
     GrammarName = grammarName;
     LoadGrammar = true;
     //logger = Logger.getLogger(getClass().getName());
 }