Beispiel #1
0
        public RandomRecommender(DataModel dataModel)
            : base(dataModel)
        {
            this.random = RandomUtils.getRandom();
            float negativeInfinity        = float.NegativeInfinity;
            float positiveInfinity        = float.PositiveInfinity;
            IEnumerator <long> enumerator = dataModel.getUserIDs();

            while (enumerator.MoveNext())
            {
                long            current = enumerator.Current;
                PreferenceArray array   = dataModel.getPreferencesFromUser(current);
                for (int i = 0; i < array.length(); i++)
                {
                    float num5 = array.getValue(i);
                    if (num5 < positiveInfinity)
                    {
                        positiveInfinity = num5;
                    }
                    if (num5 > negativeInfinity)
                    {
                        negativeInfinity = num5;
                    }
                }
            }
            this.minPref = positiveInfinity;
            this.maxPref = negativeInfinity;
        }
Beispiel #2
0
            public Features(ALSWRFactorizer factorizer)
            {
                this.dataModel   = factorizer.dataModel;
                this.numFeatures = factorizer.numFeatures;
                RandomWrapper wrapper = RandomUtils.getRandom();

                this.M = new double[this.dataModel.getNumItems()][];
                IEnumerator <long> enumerator = this.dataModel.getItemIDs();

                while (enumerator.MoveNext())
                {
                    long current = enumerator.Current;
                    int  index   = factorizer.itemIndex(current);
                    this.M[index]    = new double[this.numFeatures];
                    this.M[index][0] = this.averateRating(current);
                    for (int j = 1; j < this.numFeatures; j++)
                    {
                        this.M[index][j] = wrapper.nextDouble() * 0.1;
                    }
                }
                this.U = new double[this.dataModel.getNumUsers()][];
                for (int i = 0; i < this.U.Length; i++)
                {
                    this.U[i] = new double[this.numFeatures];
                }
            }
        protected void initialize()
        {
            int           num3;
            RandomWrapper wrapper = RandomUtils.getRandom();

            this.userVectors = new double[this.dataModel.getNumUsers()][];
            this.itemVectors = new double[this.dataModel.getNumItems()][];
            double num = this.getAveragePreference();

            for (int i = 0; i < this.userVectors.Length; i++)
            {
                this.userVectors[i]    = new double[this.rank];
                this.userVectors[i][0] = num;
                this.userVectors[i][USER_BIAS_INDEX] = 0.0;
                this.userVectors[i][ITEM_BIAS_INDEX] = 1.0;
                num3 = FEATURE_OFFSET;
                while (num3 < this.rank)
                {
                    this.userVectors[i][num3] = wrapper.nextGaussian() * NOISE;
                    num3++;
                }
            }
            for (int j = 0; j < this.itemVectors.Length; j++)
            {
                this.itemVectors[j]    = new double[this.rank];
                this.itemVectors[j][0] = 1.0;
                this.itemVectors[j][USER_BIAS_INDEX] = 1.0;
                this.itemVectors[j][ITEM_BIAS_INDEX] = 0.0;
                for (num3 = FEATURE_OFFSET; num3 < this.rank; num3++)
                {
                    this.itemVectors[j][num3] = wrapper.nextGaussian() * NOISE;
                }
            }
        }
Beispiel #4
0
        public ShipFactoryIntegrationTests()
        {
            _configMock = new Mock <IOptions <AppSettings> >(MockBehavior.Strict);
            var randomWrapper = new RandomWrapper();

            _sut = new ShipFactory(_configMock.Object, randomWrapper);
        }
        public FixedSizeSamplingIterator(int size, IEnumerator <T> source)
        {
            this.buf = new List <T>(size);
            int           n       = 0;
            RandomWrapper wrapper = RandomUtils.getRandom();

            while (source.MoveNext())
            {
                T current = source.Current;
                n++;
                if (this.buf.Count < size)
                {
                    this.buf.Add(current);
                }
                else
                {
                    int num2 = wrapper.nextInt(n);
                    if (num2 < this.buf.Count)
                    {
                        this.buf[num2] = current;
                    }
                }
            }
            this.enumerator = this.buf.GetEnumerator();
        }
Beispiel #6
0
 private static void Main(string[] args)
 {
     var seed        = new Random().Next();
     var rndSource   = new RandomWrapper(seed);
     var treeBuilder = new TreeBuilder(rndSource);
     var tree        = treeBuilder.BuildTree();
 }
        protected void initialize()
        {
            RandomWrapper random = RandomUtils.getRandom();

            userVectors = new double[dataModel.GetNumUsers()][];
            itemVectors = new double[dataModel.GetNumItems()][];

            double globalAverage = getAveragePreference();

            for (int userIndex = 0; userIndex < userVectors.Length; userIndex++)
            {
                userVectors[userIndex] = new double[rank];

                userVectors[userIndex][0] = globalAverage;
                userVectors[userIndex][USER_BIAS_INDEX] = 0; // will store user bias
                userVectors[userIndex][ITEM_BIAS_INDEX] = 1; // corresponding item feature contains item bias
                for (int feature = FEATURE_OFFSET; feature < rank; feature++)
                {
                    userVectors[userIndex][feature] = random.nextGaussian() * NOISE;
                }
            }
            for (int itemIndex = 0; itemIndex < itemVectors.Length; itemIndex++)
            {
                itemVectors[itemIndex] = new double[rank];

                itemVectors[itemIndex][0] = 1;               // corresponding user feature contains global average
                itemVectors[itemIndex][USER_BIAS_INDEX] = 1; // corresponding user feature contains user bias
                itemVectors[itemIndex][ITEM_BIAS_INDEX] = 0; // will store item bias
                for (int feature = FEATURE_OFFSET; feature < rank; feature++)
                {
                    itemVectors[itemIndex][feature] = random.nextGaussian() * NOISE;
                }
            }
        }
Beispiel #8
0
        public EntityBase(Color foreground, Color background, int glyph, Map map, bool haveVision = false, int visionRange = 20) : base(1, 1)
        {
            Animation.CurrentFrame[0].Foreground = foreground;
            Animation.CurrentFrame[0].Background = background;
            Animation.CurrentFrame[0].Glyph      = glyph;

            EntityStatus = new EntityStatus();

            Inventory = new Inventory(EntityStatus.MaxWeight);

            this.map = map;

            HaveVision = haveVision;
            if (HaveVision)
            {
                fovmap      = new FOV(map);
                VisionRange = visionRange;
            }

            Equip = new ItemBase("Pickaxe", 10f);
            Equip.ItemBehaviour = ItemBehaviourHelper.Mine();

            random = RandomNumberServiceLocator.GetService();
            logger = LoggingServiceLocator.GetService();

            ID = random.NextUint();
        }
Beispiel #9
0
        private void UpdateSeed(int newSeed)
        {
            var treeRndSource = new RandomWrapper(newSeed);
            var treeBuilder   = new TreeBuilder(treeRndSource);

            trunk       = treeBuilder.BuildTree();
            grassRandom = new RandomWrapper(newSeed);
        }
        public TreeBehaviourEngine(TreeEnvironmentConfig config, TreeState treeState)
        {
            this.config    = config ?? throw new System.ArgumentNullException(nameof(config));
            this.TreeState = treeState ?? throw new System.ArgumentNullException(nameof(treeState));

            WaterDelta = 0.125;
            rndSource  = new RandomWrapper(treeState.Seed);
        }
        protected override void prepareTraining()
        {
            int num;
            int num2;

            base.prepareTraining();
            RandomWrapper wrapper = RandomUtils.getRandom();

            this.p = new double[base.dataModel.getNumUsers()][];
            for (num = 0; num < this.p.Length; num++)
            {
                this.p[num] = new double[base.numFeatures];
                num2        = 0;
                while (num2 < RatingSGDFactorizer.FEATURE_OFFSET)
                {
                    this.p[num][num2] = 0.0;
                    num2++;
                }
                num2 = RatingSGDFactorizer.FEATURE_OFFSET;
                while (num2 < base.numFeatures)
                {
                    this.p[num][num2] = wrapper.nextGaussian() * base.randomNoise;
                    num2++;
                }
            }
            this.y = new double[base.dataModel.getNumItems()][];
            for (num = 0; num < this.y.Length; num++)
            {
                this.y[num] = new double[base.numFeatures];
                num2        = 0;
                while (num2 < RatingSGDFactorizer.FEATURE_OFFSET)
                {
                    this.y[num][num2] = 0.0;
                    num2++;
                }
                for (num2 = RatingSGDFactorizer.FEATURE_OFFSET; num2 < base.numFeatures; num2++)
                {
                    this.y[num][num2] = wrapper.nextGaussian() * base.randomNoise;
                }
            }
            this.itemsByUser = new Dictionary <int, List <int> >();
            IEnumerator <long> enumerator = base.dataModel.getUserIDs();

            while (enumerator.MoveNext())
            {
                long       current = enumerator.Current;
                int        num4    = base.userIndex(current);
                FastIDSet  set     = base.dataModel.getItemIDsFromUser(current);
                List <int> list    = new List <int>(set.size());
                this.itemsByUser[num4] = list;
                foreach (long num5 in set)
                {
                    int item = base.itemIndex(num5);
                    list.Add(item);
                }
            }
        }
Beispiel #12
0
        public GridBuilderIntegrationTests()
        {
            _configMock = new Mock <IOptions <AppSettings> >(MockBehavior.Strict);
            var randomWrapper = new RandomWrapper();
            var shipFactory   = new ShipFactory(_configMock.Object, randomWrapper);
            var grid          = new Logic.Grid.Grid();

            _sut = new GridBuilder(_configMock.Object, shipFactory, grid);
        }
Beispiel #13
0
    public float Execute()
    {
        Debug.Log("DamagePercentageUseCase");
        float damage = -target.finalMaxHP * percentage * RandomWrapper.Range(0.2f);

        new ModifyHPUseCase(target, damage).Execute();
        DamageLogger.Add(target.unitId, (int)damage);
        return(damage);
    }
Beispiel #14
0
        protected void shufflePreferences()
        {
            RandomWrapper wrapper = RandomUtils.getRandom();

            for (int i = this.cachedUserIDs.Length - 1; i > 0; i--)
            {
                int posB = wrapper.nextInt(i + 1);
                this.swapCachedPreferences(i, posB);
            }
        }
        protected void shufflePreferences()
        {
            RandomWrapper random = RandomUtils.getRandom();

            /// Durstenfeld shuffle
            for (int currentPos = cachedUserIDs.Length - 1; currentPos > 0; currentPos--)
            {
                int swapPos = random.nextInt(currentPos + 1);
                swapCachedPreferences(currentPos, swapPos);
            }
        }
        public void ChooseRandomWeighted_ReturnsRandomObjectBasedOnWeight()
        {
            var listOfObjects = new List <WeightedTestObject>
            {
                new WeightedTestObject {
                    Name = TestConst.Heavy, Weight = TestConst.WeightHeavy
                },
                new WeightedTestObject {
                    Name = TestConst.Medium, Weight = TestConst.WeightMedium
                },
                new WeightedTestObject {
                    Name = TestConst.Light, Weight = TestConst.WeightLight
                },
                new WeightedTestObject {
                    Name = TestConst.Empty, Weight = TestConst.WeightNone
                },
            };

            int testRuns = 100;
            var stats    = new Dictionary <string, int>();
            var rand     = new RandomWrapper();

            for (int i = 0; i < testRuns; i++)
            {
                var selection = rand.ChooseRandomWeighted(listOfObjects);

                Assert.IsNotNull(selection);

                Debug.Print("Random select: {0}", selection.Name);

                if (stats.ContainsKey(selection.Name))
                {
                    stats[selection.Name] += 1;
                }
                else
                {
                    stats.Add(selection.Name, 1);
                }
            }

            foreach (var item in stats)
            {
                Debug.Print("{0}: {1}", item.Key, item.Value);
            }

            Assert.IsTrue(stats.ContainsKey(TestConst.Heavy));
            Assert.IsTrue(stats.ContainsKey(TestConst.Medium));
            Assert.IsTrue(stats.ContainsKey(TestConst.Light));
            Assert.IsTrue(stats.ContainsKey(TestConst.Empty) == false);

            Assert.IsTrue(stats[TestConst.Heavy] > stats[TestConst.Medium]);
            Assert.IsTrue(stats[TestConst.Medium] > stats[TestConst.Light]);
        }
Beispiel #17
0
 void Start()
 {
     rb2D = GetComponent <Rigidbody2D>();
     rng  = new RandomWrapper();
     foreach (float degreeDirection in possibleDirectionsAsDegrees)
     {
         float radian = degreeDirection * Mathf.Deg2Rad;
         possibleVectorDirections.Add(new Vector2(
                                          Mathf.Cos(radian), Mathf.Sin(radian)
                                          ));
     }
     MoveToRandomDirection();
 }
        public void ChooseRandomWeighted_WithZeroWeightedItemsNotAllowed_ReturnsNull()
        {
            var listOfObjects = new List <WeightedTestObject>
            {
                new WeightedTestObject {
                    Name = TestConst.Empty, Weight = TestConst.WeightNone
                }
            };

            var selection = new RandomWrapper().ChooseRandomWeighted(listOfObjects, itemsWithZeroWeightCanBeSelected: false);

            Assert.IsNull(selection);
        }
Beispiel #19
0
        public GameLogicIntegrationTests()
        {
            _configMock = new Mock <IOptions <AppSettings> >(MockBehavior.Strict);
            var settingsChecker     = new SettingsChecker(_configMock.Object);
            var randomWrapper       = new RandomWrapper();
            var shipFactory         = new ShipFactory(_configMock.Object, randomWrapper);
            var grid                = new Logic.Grid.Grid();
            var gridBuilder         = new GridBuilder(_configMock.Object, shipFactory, grid);
            var coordinateValidator = new CoordinateValidator();
            var coordinateParser    = new CoordinateParser(coordinateValidator);

            _sut = new GameLogic(settingsChecker, gridBuilder, coordinateParser);
        }
Beispiel #20
0
 public SamplingLongPrimitiveIterator(RandomWrapper random, IEnumerator <long> enumerator, double samplingRate)
 {
     if (enumerator == null)
     {
         throw new ArgumentException("enumerator");
     }
     if ((samplingRate <= 0.0) || (samplingRate > 1.0))
     {
         throw new ArgumentException("samplingRate");
     }
     this.geometricDistribution = new PascalDistribution(random.getRandomGenerator(), 1, samplingRate);
     this.enumerator            = enumerator;
     this.SkipNext();
 }
Beispiel #21
0
        public SamplinglongPrimitiveIterator(RandomWrapper random, IEnumerator <long> enumerator, double samplingRate)
        {
            if (enumerator == null)
            {
                throw new ArgumentException("enumerator");
            }
            if (!(samplingRate > 0.0 && samplingRate <= 1.0))
            {
                throw new ArgumentException("samplingRate");
            }
            //Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0, "Must be: 0.0 < samplingRate <= 1.0");
            // Geometric distribution is special case of negative binomial (aka Pascal) with r=1:
            geometricDistribution = new PascalDistribution(random.getRandomGenerator(), 1, samplingRate);
            this.enumerator       = enumerator;

            SkipNext();
        }
Beispiel #22
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            var actions = new List <IAction>
            {
                new MoveAction(),
                new ShrinkSizeAction(),
                new ChangeColorAction(new ColorRgba(255, 255, 0), new ColorRgba(0, 0, 255)),
                new FadeAction(255, 0)
            };

            var randomGenerator = new RandomWrapper();

            _particleEmitter1 = new Emitter(
                new EmitterConfig
            {
                EmitterShape             = new PointEmitter(new ThreeSixty(50, 100, randomGenerator)),
                InitialColorCalculator   = new Varied(new ColorRgba(255, 255, 0), new ColorRgba(20, 20, 20), randomGenerator),
                FinalColorCalculator     = new Varied(new ColorRgba(0, 0, 255), new ColorRgba(20, 20, 20), randomGenerator),
                InitialSizeCalculator    = new RandomBetweenXAndY(0.1f, 2.0f, randomGenerator),
                EmissionRatePerSecond    = 200,
                MaximumNumberOfParticles = 1000,
                Actions = actions
            });
            _particleEmitter1.Location = new SneakyParticleSystem.Vector2(100.0f, 100.0f);

            _particleEmitter2 = new Emitter(
                new EmitterConfig
            {
                EmitterShape             = new CircleEmitter(100.0f, new Normal(1, 100, randomGenerator), randomGenerator),
                InitialColorCalculator   = new Simple(new ColorRgba(255, 0, 0)),
                FinalColorCalculator     = new Simple(new ColorRgba(255, 255, 0)),
                InitialSizeCalculator    = new RandomBetweenXAndY(0.1f, 2.0f, randomGenerator),
                EmissionRatePerSecond    = 200,
                MaximumNumberOfParticles = 1000,
                Actions = actions
            });
            _particleEmitter2.Location = new SneakyParticleSystem.Vector2(400.0f, 300.0f);

            _particleSystemRenderer = new ParticleSystemRenderer();
            _particleSystemRenderer.LoadContent(Content);
        }
        /**
         * @param dataModel
         *          {@link DataModel} which provides users
         * @param clusterSimilarity
         *          {@link ClusterSimilarity} used to compute cluster similarity
         * @param clusteringThreshold
         *          clustering similarity threshold; clusters will be aggregated into larger clusters until the next
         *          two nearest clusters' similarity drops below this threshold
         * @param samplingRate
         *          percentage of all cluster-cluster pairs to consider when finding next-most-similar clusters.
         *          Decreasing this value from 1.0 can increase performance at the cost of accuracy
         * @throws IllegalArgumentException
         *           if arguments are {@code null}, or {@code clusteringThreshold} is {@link Double#NaN},
         *           or samplingRate is {@link Double#NaN} or nonpositive or greater than 1.0
         */

        public TreeClusteringRecommender(DataModel dataModel,
                                         ClusterSimilarity clusterSimilarity,
                                         double clusteringThreshold,
                                         double samplingRate)
            : base(dataModel)
        {
            //Preconditions.checkArgument(!Double.IsNaN(clusteringThreshold), "clusteringThreshold must not be NaN");
            //Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0, "samplingRate is invalid: %f", samplingRate);
            random = RandomUtils.getRandom();
            this.clusterSimilarity     = clusterSimilarity; //Preconditions.checkNotNull(clusterSimilarity);
            this.numClusters           = int.MinValue;      //Integer.MIN_VALUE;
            this.clusteringThreshold   = clusteringThreshold;
            this.clusteringByThreshold = true;
            this.samplingRate          = samplingRate;
            this.refreshHelper         = new RefreshHelper(buildClusters);
            refreshHelper.addDependency(dataModel);
            refreshHelper.addDependency(clusterSimilarity);
            buildClusters();
        }
Beispiel #24
0
        public static void FuckUpSteamData()
        {
            if (STEAM_NAME == null || STEAM_ID_HOLDER == null || STEAM_ID_FIELD == null)
            {
                Console.WriteLine("ERROR: {0} {1} {2}", STEAM_NAME != null, STEAM_ID_HOLDER != null, STEAM_ID_FIELD != null);
                return;
            }

            STEAM_NAME.SetValue(null, RandomWrapper.GenerateString(8), null);

            if (holder != null)
            {
                var id    = (CSteamID)STEAM_ID_FIELD.GetValue(holder, null);
                var oldId = id.m_SteamID;
                id        = new CSteamID(new AccountID_t((uint)UnityEngine.Random.Range(0, int.MaxValue)), id.GetEUniverse(), id.GetEAccountType());
                CurrentID = id.m_SteamID;
                STEAM_ID_FIELD.SetValue(holder, id, null);
            }
        }
        /**
         * @param dataModel
         *          {@link DataModel} which provdes users
         * @param clusterSimilarity
         *          {@link ClusterSimilarity} used to compute cluster similarity
         * @param numClusters
         *          desired number of clusters to create
         * @param samplingRate
         *          percentage of all cluster-cluster pairs to consider when finding next-most-similar clusters.
         *          Decreasing this value from 1.0 can increase performance at the cost of accuracy
         * @throws IllegalArgumentException
         *           if arguments are {@code null}, or {@code numClusters} is less than 2, or samplingRate
         *           is {@link Double#NaN} or nonpositive or greater than 1.0
         */

        public TreeClusteringRecommender(DataModel dataModel,
                                         ClusterSimilarity clusterSimilarity,
                                         int numClusters,
                                         double samplingRate)
            : base(dataModel)
        {
            //Preconditions.checkArgument(numClusters >= 2, "numClusters must be at least 2");
            //Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0,
            //  "samplingRate is invalid: %f", samplingRate);
            random = RandomUtils.getRandom();
            this.clusterSimilarity     = clusterSimilarity;//Preconditions.checkNotNull(clusterSimilarity);
            this.numClusters           = numClusters;
            this.clusteringThreshold   = Double.NaN;
            this.clusteringByThreshold = false;
            this.samplingRate          = samplingRate;
            this.refreshHelper         = new RefreshHelper(buildClusters);
            refreshHelper.addDependency(dataModel);
            refreshHelper.addDependency(clusterSimilarity);
            buildClusters();
        }
Beispiel #26
0
        protected override void Initialize()
        {
            // Generally you don't want to hide the mouse from the user
            IsMouseVisible = true;

            // Finish the initialization of SadConsole
            base.Initialize();

            RandomWrapper randomWrapper = new RandomWrapper(2);

            RandomNumberServiceLocator.Provide(randomWrapper);

            // Create the map
            AdventureScreen = new AdventureScreen();
            AdventureScreen.LoadMap(MapGenerator.Generate(200, 200));
            AdventureScreen.SpawnPlayer();

            SadConsole.ControlsConsole startingConsole = new SadConsole.ControlsConsole(SCREEN_WIDTH, SCREEN_HEIGHT);

            var bt1 = new SadConsole.Controls.Button(5);

            startingConsole.Add(bt1);

            SadConsole.Global.CurrentScreen = startingConsole;

            SadConsole.Global.CurrentScreen.Children.Add(AdventureScreen);

            //SimplexNoiseViewer simplexNoiseViewer = new SimplexNoiseViewer(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
            //simplexNoiseViewer.LoadMap(200, 200, 0.03f);
            //SadConsole.Global.CurrentScreen = simplexNoiseViewer;

            //SadConsole.Window window = new SadConsole.Window(10, 10);
            //window.Title = "status";
            //window.Dragable = true;
            //window.Show();
            //SadConsole.Global.CurrentScreen = startingConsole;
            //SadConsole.Global.CurrentScreen.Children.Add(window);
        }
Beispiel #27
0
        public static GameState MakeInitialGameState(List <Player> players, TurnCount totalRounds, GridSize gridSize, ICollisions iCollisions, IEndGame iEndGame)
        {
            var gameState = new GameState()
            {
                Round       = 1,
                TotalRounds = totalRounds,
                GameOver    = false,
                GridSize    = gridSize,
                Players     = new List <Player>(),
                Collisions  = iCollisions,
                EndGame     = iEndGame
            };

            foreach (var player in players)
            {
                int x = RandomWrapper.RandomNumber(0, gameState.GridSize.Cols);
                int y = RandomWrapper.RandomNumber(0, gameState.GridSize.Rows);
                player.Destroyed = false;
                player.Position  = new Position(x, y);
                gameState.Players.Add(player);
            }
            return(gameState);
        }
        protected virtual void prepareTraining()
        {
            RandomWrapper random = RandomUtils.getRandom();

            userVectors = new double[dataModel.GetNumUsers()][]; //numFeatures
            itemVectors = new double[dataModel.GetNumItems()][];

            double globalAverage = getAveragePreference();

            for (int userIndex = 0; userIndex < userVectors.Length; userIndex++)
            {
                userVectors[userIndex] = new double[numFeatures];

                userVectors[userIndex][0] = globalAverage;
                userVectors[userIndex][USER_BIAS_INDEX] = 0; // will store user bias
                userVectors[userIndex][ITEM_BIAS_INDEX] = 1; // corresponding item feature contains item bias
                for (int feature = FEATURE_OFFSET; feature < numFeatures; feature++)
                {
                    userVectors[userIndex][feature] = random.nextGaussian() * randomNoise;
                }
            }
            for (int itemIndex = 0; itemIndex < itemVectors.Length; itemIndex++)
            {
                itemVectors[itemIndex] = new double[numFeatures];

                itemVectors[itemIndex][0] = 1;               // corresponding user feature contains global average
                itemVectors[itemIndex][USER_BIAS_INDEX] = 1; // corresponding user feature contains user bias
                itemVectors[itemIndex][ITEM_BIAS_INDEX] = 0; // will store item bias
                for (int feature = FEATURE_OFFSET; feature < numFeatures; feature++)
                {
                    itemVectors[itemIndex][feature] = random.nextGaussian() * randomNoise;
                }
            }

            cachePreferences();
            shufflePreferences();
        }
Beispiel #29
0
        protected virtual void prepareTraining()
        {
            int           num3;
            RandomWrapper wrapper = RandomUtils.getRandom();

            this.userVectors = new double[this.dataModel.getNumUsers()][];
            this.itemVectors = new double[this.dataModel.getNumItems()][];
            double num = this.getAveragePreference();

            for (int i = 0; i < this.userVectors.Length; i++)
            {
                this.userVectors[i]    = new double[this.numFeatures];
                this.userVectors[i][0] = num;
                this.userVectors[i][USER_BIAS_INDEX] = 0.0;
                this.userVectors[i][ITEM_BIAS_INDEX] = 1.0;
                num3 = FEATURE_OFFSET;
                while (num3 < this.numFeatures)
                {
                    this.userVectors[i][num3] = wrapper.nextGaussian() * this.randomNoise;
                    num3++;
                }
            }
            for (int j = 0; j < this.itemVectors.Length; j++)
            {
                this.itemVectors[j]    = new double[this.numFeatures];
                this.itemVectors[j][0] = 1.0;
                this.itemVectors[j][USER_BIAS_INDEX] = 1.0;
                this.itemVectors[j][ITEM_BIAS_INDEX] = 0.0;
                for (num3 = FEATURE_OFFSET; num3 < this.numFeatures; num3++)
                {
                    this.itemVectors[j][num3] = wrapper.nextGaussian() * this.randomNoise;
                }
            }
            this.cachePreferences();
            this.shufflePreferences();
        }
Beispiel #30
0
 void Awake()
 {
     main = this;
     rng  = new RandomWrapper();
 }