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

📄 simplegraphexample.java

📁 常用机器学习算法,java编写源代码,内含常用分类算法,包括说明文档
💻 JAVA
字号:
/* Copyright (C) 2003 Univ. of Massachusetts Amherst, Computer Science Dept.   This file is part of "MALLET" (MAchine Learning for LanguagE Toolkit).   http://www.cs.umass.edu/~mccallum/mallet   This software is provided under the terms of the Common Public License,   version 1.0, as published by http://www.opensource.org.  For further   information, see the file `LICENSE' included with this distribution. */package edu.umass.cs.mallet.grmm.examples;import edu.umass.cs.mallet.grmm.*;import java.util.Random;/** * Created: Aug 13, 2004 * * @author <A HREF="mailto:casutton@cs.umass.edu>casutton@cs.umass.edu</A> * @version $Id: SimpleGraphExample.java,v 1.1 2004/08/13 20:20:44 casutton Exp $ */public class SimpleGraphExample {  public static void main (String[] args)  {    // STEP 1: Create the graph    Variable[] allVars = {      new Variable (2),      new Variable (2),      new Variable (2),      new Variable (2)    };    UndirectedModel mdl = new UndirectedModel (allVars);    // Create a diamond graph, with random potentials    Random r = new Random (42);    for (int i = 0; i < allVars.length; i++) {      double[] ptlarr = new double [4];      for (int j = 0; j < ptlarr.length; j++)        ptlarr [j] = Math.abs (r.nextDouble ());      Variable v1 = allVars [i];      Variable v2 = allVars [(i + 1) % allVars.length];      mdl.addEdgeWithPotential (v1, v2, ptlarr);    }    // STEP 2: Compute marginals    Inferencer inf = new JunctionTreeInferencer ();    inf.computeMarginals (mdl);    // STEP 3: Collect the results    //   We'll just print them out    for (int varnum = 0; varnum < allVars.length; varnum++) {      Variable var = allVars[varnum];      DiscretePotential ptl = inf.lookupMarginal (var);      for (int outcome = 0; outcome < 2; outcome++) {        Assignment assn = new Assignment (var, outcome);        System.out.println (var+"  "+outcome+"   "+ptl.phi (assn));      }      System.out.println ();    }  }}

⌨️ 快捷键说明

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