⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 potentialfactory.java

📁 是实现关系型贝叶斯网络一中机器学习算法
💻 JAVA
字号:
package rmn;import java.io.Serializable;public class PotentialFactory implements Serializable {  // weight matrix  protected Matrix m_weights;  // last time the weights were modified  protected int m_nTime;  // average log weight matrix (as updated by VotedPeceptron)  protected Matrix m_avgwt;  // true counts matrix  protected Matrix m_matTrue;  // inference counts matrix  protected Matrix m_matInf;  // # of instantiated potentials  int m_nPots;  // true if further used in inference  boolean m_bInference;  // true if used in current factor graph (see VotedPerceptron)  boolean m_bUsed;  public PotentialFactory()  {    m_weights = m_avgwt = m_matTrue = m_matInf = null;    m_nPots = 0;    m_bInference = true;    m_bUsed = false;    m_nTime = 0;  }  public PotentialFactory(Matrix matrix)  {    m_weights = matrix;    m_avgwt = m_matTrue = m_matInf = null;    m_nPots = 0;    m_bInference = true;    m_bUsed = false;    m_nTime = 0;  }  public Potential newInstance()  {    m_nPots++;    return new Potential(this);  }  public Matrix getWeightMatrix()  {    return m_weights;  }  public Matrix newWeightMatrix()  {    return m_weights.newMatrix();  }  public int size()  {    return m_weights.size();  }  public int instanceCount()  {    return m_nPots;  }  public void setInference(boolean bInference)  {    m_bInference = bInference;  }  public void setLearning(boolean bLearning)  {    if (bLearning) {      // allocate counts      m_avgwt = m_weights.newMatrix();      m_matTrue = m_weights.newMatrix();      m_matInf = m_weights.newMatrix();      initCounts();      m_nTime = 0;    }    else {      // deallocate counts      m_avgwt = m_matTrue = m_matInf = null;    }  }  public boolean isLearning()  {    return m_matTrue != null;  }  public void initWeights()  {    m_weights.fill(1);    m_avgwt.fill(0);  }  public void initCounts()  {    m_matTrue.fill(0);    m_matInf.fill(0);    m_bUsed = false;  }  public void incTrueCounts(int[] pos)  {    m_matTrue.inc(pos);  }  public void incInfCounts(int[] pos)  {    m_matInf.inc(pos);  }  public void updateWeights(int nTime, double rate)  {    // accumulate old weights into average    m_avgwt.add_log(m_weights, nTime - m_nTime);    // perceptron delta rule    m_weights.add_sub(m_matTrue, m_matInf, rate);    m_nTime = nTime;  }  public void averageWeights(int nTime)  {    // accumulate old weights into average    m_avgwt.add_log(m_weights, nTime - m_nTime);    m_nTime = nTime;  }  public void setWeightsAverage(int n)  {    m_weights = m_avgwt.exp_avg(n);  }  // by default, all potentials have a fix arity  public boolean hasVariableArity()  {    return false;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -