Skip to content

Commit

Permalink
Server gotowy, domyslnie juz malo zmian w C#, 0 w interfejsie
Browse files Browse the repository at this point in the history
  • Loading branch information
kudkudak committed May 21, 2013
1 parent 1569ce9 commit 242bf7c
Show file tree
Hide file tree
Showing 26 changed files with 3,136 additions and 21,588 deletions.
11 changes: 11 additions & 0 deletions server-predictor-tests/server-predictor-tests/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ public void log_warning(string message)
{
this.log("WARNING:" + message);
}
public void log_2darray<T>(T[,] arr)
{
var rowCount = arr.GetLength(0);
var colCount = arr.GetLength(1);
for (int row = 0; row < rowCount; row++)
{
for (int col = 0; col < colCount; col++)
Console.Write(String.Format("{0}\t", arr[row, col]));
Console.WriteLine();
}
}
public void log_array<T>(T[] array){
this.log("(", false);
foreach (var t in array) Console.Write(t + " , ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

namespace server_predictor_tests
{
//Model for calculating pairwise factors. For now is trivial //
///<summary>
///Model for calculating pairwise factors. For now is trivial
///</summary>
class PairwiseModelR
{
public static REngine engine
Expand All @@ -26,8 +28,6 @@ public PairwiseModelR(string name)
pairwiseFactors = new ArrayList();
}



// data_file_name - train
public void init()
{
Expand Down
10 changes: 6 additions & 4 deletions server-predictor-tests/server-predictor-tests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ class Program
static void Main(string[] args)
{

Thread th = PredictionDaemon.Instance.getDaemon();
th.Priority = ThreadPriority.Highest;
th.Start();

//Set server configuration, for demonstration purposes, server will be merged with the client//
ServerCore.Instance.serverConfiguration = new ServerConfiguration { simulation_start_minute = 1 };
ServerCore.Instance.getDaemon().Start();

Logger.Instance.log("Waiting for data");
Logger.Instance.log_2darray(ServerCore.Instance.fetchPrediction());
Logger.Instance.log("Data available");
while (true) ;
}
}
Expand Down
16,843 changes: 117 additions & 16,726 deletions server-predictor-tests/server-predictor-tests/bin/Debug/GeneratedSource/Model0_Gibbs.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
using System;
using MicrosoftResearch.Infer;
using MicrosoftResearch.Infer.Maths;
using MicrosoftResearch.Infer.Distributions;
using MicrosoftResearch.Infer.Collections;
using MicrosoftResearch.Infer.Factors;
using System.Collections.Generic;

namespace MicrosoftResearch.Infer.Models.User
{
/// <summary>
/// Generated algorithm for performing inference
/// </summary>
/// <remarks>
/// The easiest way to use this class is to wrap an instance in a CompiledAlgorithm object and use
/// the methods on CompiledAlgorithm to set parameters and execute inference.
///
/// If you instead wish to use this class directly, you must perform the following steps:
/// 1) Create an instance of the class
/// 2) Set the value of any externally-set fields e.g. data, priors
/// 3) Call the Execute(numberOfIterations) method
/// 4) Use the XXXMarginal() methods to retrieve posterior marginals for different variables.
///
/// Generated by Infer.NET 2.5 at 04:18 on 21 maja 2013.
/// </remarks>
public partial class Model10_Gibbs : IGeneratedAlgorithm
{
#region Fields
/// <summary>Field backing the NumberOfIterationsDone property</summary>
private int numberOfIterationsDone;
/// <summary>Field backing the vVector11 property</summary>
private Vector VVector11;
/// <summary>The number of iterations last computed by Changed_vVector11. Set this to zero to force re-execution of Changed_vVector11</summary>
public int Changed_vVector11_iterationsDone;
/// <summary>The number of iterations last computed by Changed_vVector11_Init_numberOfIterationsDecreased. Set this to zero to force re-execution of Changed_vVector11_Init_numberOfIterationsDecreased</summary>
public int Changed_vVector11_Init_numberOfIterationsDecreased_iterationsDone;
/// <summary>True if Changed_vVector11_Init_numberOfIterationsDecreased has performed initialisation. Set this to false to force re-execution of Changed_vVector11_Init_numberOfIterationsDecreased</summary>
public bool Changed_vVector11_Init_numberOfIterationsDecreased_isInitialised;
/// <summary>The number of iterations last computed by Changed_numberOfIterationsDecreased_vVector11. Set this to zero to force re-execution of Changed_numberOfIterationsDecreased_vVector11</summary>
public int Changed_numberOfIterationsDecreased_vVector11_iterationsDone;
/// <summary>Message to marginal of 'vint23'</summary>
public GibbsMarginal<Discrete,int> vint23_marginal_F;
public PointMass<Vector> vVector11_marginal;
#endregion

#region Properties
/// <summary>The number of iterations done from the initial state</summary>
public int NumberOfIterationsDone
{ get {
return this.numberOfIterationsDone;
}
}

/// <summary>The externally-specified value of 'vVector11'</summary>
public Vector vVector11
{ get {
return this.VVector11;
}
set {
this.VVector11 = value;
this.numberOfIterationsDone = 0;
this.Changed_vVector11_Init_numberOfIterationsDecreased_iterationsDone = 0;
this.Changed_numberOfIterationsDecreased_vVector11_iterationsDone = 0;
this.Changed_vVector11_iterationsDone = 0;
}
}

#endregion

#region Methods
/// <summary>Get the observed value of the specified variable.</summary>
/// <param name="variableName">Variable name</param>
public object GetObservedValue(string variableName)
{
if (variableName=="vVector11") {
return this.vVector11;
}
throw new ArgumentException("Not an observed variable name: "+variableName);
}

/// <summary>Set the observed value of the specified variable.</summary>
/// <param name="variableName">Variable name</param>
/// <param name="value">Observed value</param>
public void SetObservedValue(string variableName, object value)
{
if (variableName=="vVector11") {
this.vVector11 = (Vector)value;
return ;
}
throw new ArgumentException("Not an observed variable name: "+variableName);
}

/// <summary>The marginal distribution of the specified variable.</summary>
/// <param name="variableName">Variable name</param>
public object Marginal(string variableName)
{
if (variableName=="vint23") {
return this.Vint23Marginal();
}
if (variableName=="vVector11") {
return this.VVector11Marginal();
}
throw new ArgumentException("This class was not built to infer "+variableName);
}

public T Marginal<T>(string variableName)
{
return Distribution.ChangeType<T>(this.Marginal(variableName));
}

/// <summary>The query-specific marginal distribution of the specified variable.</summary>
/// <param name="variableName">Variable name</param>
/// <param name="query">QueryType name. For example, GibbsSampling answers 'Marginal', 'Samples', and 'Conditionals' queries</param>
public object Marginal(string variableName, string query)
{
if (query=="Marginal") {
return this.Marginal(variableName);
}
if ((variableName=="vint23")&&(query=="Samples")) {
return this.Vint23Samples();
}
throw new ArgumentException(((("This class was not built to infer \'"+variableName)+"\' with query \'")+query)+"\'");
}

public T Marginal<T>(string variableName, string query)
{
return Distribution.ChangeType<T>(this.Marginal(variableName, query));
}

/// <summary>Update all marginals, by iterating message passing the given number of times</summary>
/// <param name="numberOfIterations">The number of times to iterate each loop</param>
/// <param name="initialise">If true, messages that initialise loops are reset when observed values change</param>
private void Execute(int numberOfIterations, bool initialise)
{
if (numberOfIterations<this.Changed_numberOfIterationsDecreased_vVector11_iterationsDone) {
this.Changed_vVector11_Init_numberOfIterationsDecreased_isInitialised = false;
this.Changed_numberOfIterationsDecreased_vVector11_iterationsDone = 0;
}
this.Changed_vVector11_Init_numberOfIterationsDecreased(initialise);
this.Changed_numberOfIterationsDecreased_vVector11(numberOfIterations);
this.Changed_vVector11();
this.numberOfIterationsDone = numberOfIterations;
}

public void Execute(int numberOfIterations)
{
this.Execute(numberOfIterations, true);
}

public void Update(int additionalIterations)
{
this.Execute(this.numberOfIterationsDone+additionalIterations, false);
}

private void OnProgressChanged(ProgressChangedEventArgs e)
{
// Make a temporary copy of the event to avoid a race condition
// if the last subscriber unsubscribes immediately after the null check and before the event is raised.
EventHandler<ProgressChangedEventArgs> handler = this.ProgressChanged;
if (handler!=null) {
handler(this, e);
}
}

/// <summary>Reset all messages to their initial values. Sets NumberOfIterationsDone to 0.</summary>
public void Reset()
{
this.Execute(0);
}

/// <summary>Computations that depend on the observed value of vVector11 and must reset on changes to numberOfIterationsDecreased</summary>
/// <param name="initialise">If true, reset messages that initialise loops</param>
public void Changed_vVector11_Init_numberOfIterationsDecreased(bool initialise)
{
if ((this.Changed_vVector11_Init_numberOfIterationsDecreased_iterationsDone==1)&&((!initialise)||this.Changed_vVector11_Init_numberOfIterationsDecreased_isInitialised)) {
return ;
}
this.vint23_marginal_F = new GibbsMarginal<Discrete,int>(Discrete.Uniform(this.VVector11.Count), 100, 5, true, true, false);
this.Changed_vVector11_Init_numberOfIterationsDecreased_iterationsDone = 1;
this.Changed_vVector11_Init_numberOfIterationsDecreased_isInitialised = true;
this.Changed_numberOfIterationsDecreased_vVector11_iterationsDone = 0;
}

/// <summary>Computations that depend on the observed value of numberOfIterationsDecreased and vVector11</summary>
/// <param name="numberOfIterations">The number of times to iterate each loop</param>
public void Changed_numberOfIterationsDecreased_vVector11(int numberOfIterations)
{
if (this.Changed_numberOfIterationsDecreased_vVector11_iterationsDone==numberOfIterations) {
return ;
}
// Messages from uses of 'vint23'
Discrete[] vint23_uses_B = default(Discrete[]);
// Create array for 'vint23_uses' Backwards messages.
vint23_uses_B = new Discrete[0];
// Message from definition of 'vint23'
Discrete vint23_F = ArrayHelper.MakeUniform<Discrete>(Discrete.Uniform(this.VVector11.Count));
// Message to 'vint23' from Discrete factor
vint23_F = DiscreteFromDirichletOp.SampleAverageConditional(this.VVector11, vint23_F);
for(int iteration = this.Changed_numberOfIterationsDecreased_vVector11_iterationsDone; iteration<numberOfIterations; iteration++) {
// Message to 'vint23_marginal' from UsesEqualDef factor
this.vint23_marginal_F = UsesEqualDefGibbsOp<int>.MarginalGibbs<Discrete>(vint23_uses_B, vint23_F, this.vint23_marginal_F);
this.OnProgressChanged(new ProgressChangedEventArgs(iteration));
}
// Message to 'vint23_marginal' from UsesEqualDef factor
this.vint23_marginal_F = UsesEqualDefGibbsOp<int>.MarginalGibbs<Discrete>(vint23_uses_B, vint23_F, this.vint23_marginal_F);
this.Changed_numberOfIterationsDecreased_vVector11_iterationsDone = numberOfIterations;
}

/// <summary>
/// Returns the Samples for 'vint23' given by the current state of the
/// message passing algorithm.
/// </summary>
/// <returns>The Samples</returns>
public IList<int> Vint23Samples()
{
return this.vint23_marginal_F.Samples;
}

/// <summary>
/// Returns the Marginal for 'vint23' given by the current state of the
/// message passing algorithm.
/// </summary>
/// <returns>The Marginal</returns>
public Discrete Vint23Marginal()
{
return this.vint23_marginal_F.Distribution;
}

/// <summary>Computations that depend on the observed value of vVector11</summary>
public void Changed_vVector11()
{
if (this.Changed_vVector11_iterationsDone==1) {
return ;
}
this.vVector11_marginal = new PointMass<Vector>(this.VVector11);
this.Changed_vVector11_iterationsDone = 1;
}

/// <summary>
/// Returns the marginal distribution for 'vVector11' given by the current state of the
/// message passing algorithm.
/// </summary>
/// <returns>The marginal distribution</returns>
public PointMass<Vector> VVector11Marginal()
{
return this.vVector11_marginal;
}

#endregion

#region Events
/// <summary>Event that is fired when the progress of inference changes, typically at the end of one iteration of the inference algorithm.</summary>
public event EventHandler<ProgressChangedEventArgs> ProgressChanged;
#endregion

}

}
Loading

0 comments on commit 242bf7c

Please sign in to comment.