Welcome to mirror list, hosted at ThFree Co, Russian Federation.

VowpalWabbitInterface.cs « cs_test - github.com/moses-smt/vowpal_wabbit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e6366f0eb93f7f88e1b2152e4a967a3d4c20cfce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace Microsoft.Research.MachineLearning
{
    public sealed class VowpalWabbitInterface
    {
        public class FeatureSpace
        {
            public string Name;
            public Feature[] Features;
        }

        public class Feature
        {
            public float X;
            public UInt32 WeightIndex;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct FEATURE_SPACE
        {
            public byte name;
            public IntPtr features;
            public int len;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct FEATURE
        {
            public float x;
            public uint weight_index;
        }

        [DllImport("libvw.dll", EntryPoint="VW_Initialize", CallingConvention=CallingConvention.StdCall)]
        public static extern IntPtr Initialize(string arguments);

        [DllImport("libvw.dll", EntryPoint="VW_Finish", CallingConvention=CallingConvention.StdCall)]
        public static extern void Finish(IntPtr vw);

        [DllImport("libvw.dll", EntryPoint = "VW_ImportExample", CallingConvention = CallingConvention.StdCall)]
        public static extern IntPtr ImportExample(IntPtr vw,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)]
            FEATURE_SPACE[] features,
            int length);

        [DllImport("libvw.dll", EntryPoint="VW_ReadExample", CallingConvention=CallingConvention.StdCall)]
        public static extern IntPtr ReadExample(IntPtr vw, string exampleString);

        [DllImport("libvw.dll", EntryPoint="VW_FinishExample", CallingConvention=CallingConvention.StdCall)]
        public static extern void FinishExample(IntPtr vw, IntPtr example);

        [DllImport("libvw.dll", EntryPoint = "VW_HashSpace", CallingConvention = CallingConvention.StdCall)]
        public static extern uint HashSpace(IntPtr vw, string s);

        [DllImport("libvw.dll", EntryPoint = "VW_HashFeature", CallingConvention = CallingConvention.StdCall)]
        public static extern uint HashFeature(IntPtr vw, string s, ulong u);

        [DllImport("libvw.dll", EntryPoint="VW_Learn", CallingConvention=CallingConvention.StdCall)]
        public static extern float Learn(IntPtr vw, IntPtr example);
    }
}