Example #1
0
        private void SaveTrainSession(Guid trainSessionId, TrainSessionState sessionState,
                                      bool inUse = false, ModelSummary modelSummary = null, string errorMessage = null)
        {
            Guid mlModelStateId = TrainSessionStateMapping[sessionState];
            var  updateQuery    = (Update) new Update(_userConnection, "MLTrainSession")
                                  .Set("StateId", Column.Const(mlModelStateId))
                                  .Set("Error", Column.Parameter(errorMessage ?? string.Empty))
                                  .Set("TrainedOn", Column.Parameter(DateTime.UtcNow))
                                  .Where("Id").IsEqual(Column.Parameter(trainSessionId));

            if (inUse)
            {
                updateQuery = updateQuery.Set("InUse", Column.Parameter(true));
            }
            if (modelSummary != null)
            {
                string serializedFeatureImportances = JsonConvert.SerializeObject(modelSummary.FeatureImportances);
                updateQuery = updateQuery
                              .Set("TrainSetSize", Column.Const(modelSummary.DataSetSize))
                              .Set("InstanceMetric", Column.Parameter(modelSummary.Metric))
                              .Set("TrainingTimeMinutes", Column.Const(modelSummary.TrainingTimeMinutes))
                              .Set("FeatureImportances", Column.Parameter(serializedFeatureImportances));
            }
            updateQuery.Execute();
        }
Example #2
0
        private void SaveAcceptedSession(Guid mlModelId, Guid trainSessionId, ModelSummary modelSummary)
        {
            Update updateQuery = (Update) new Update(_userConnection, "MLTrainSession")
                                 .Set("InUse", Column.Parameter(false))
                                 .Where("MLModelId").IsEqual(Column.Parameter(mlModelId));

            updateQuery.Execute();
            SaveTrainSession(trainSessionId, TrainSessionState.Done, true, modelSummary);
        }
    public static ModelSummary Load(DbContext context)
    {
        var adapter       = (IObjectContextAdapter)context;
        var objectContext = adapter.ObjectContext;

        var summary = new ModelSummary();
        var items   = objectContext.MetadataWorkspace.GetItems(DataSpace.SSpace);

        summary.Entities =
            objectContext.MetadataWorkspace.GetItems(DataSpace.SSpace)
            .OfType <EntityType>()
            .ToDictionary(et => et.Name);
        return(summary);
    }
Example #4
0
        /// <summary>
        /// Queries for the actual model state and updates it in database.
        /// </summary>
        public void UpdateModelState()
        {
            Guid modelId   = _modelConfig.Id;
            Guid sessionId = _modelConfig.TrainSessionId;

            sessionId.CheckArgumentEmpty("MLModel.TrainSessionId");
            GetSessionInfoResponse response;

            try {
                response = _proxy.GetTrainingSessionInfo(sessionId);
            } catch (Exception e) {
                UpdateModelOnError(_modelConfig.Id, e.Message);
                throw;
            }
            TrainSessionState newSessionState = response.SessionState;

            _log.Info($"For model {modelId} new model state - {newSessionState}, old was {_modelConfig.CurrentState}");
            if (FiniteStates.Contains(newSessionState))
            {
                UpdateTriedToTrainOn(modelId);
            }
            if (newSessionState == TrainSessionState.Done)
            {
                try {
                    ModelSummary modelSummary  = response.ModelSummary;
                    var          ignoresMetric = GetIsTrainSessionIgnoresMetric(sessionId);
                    if (ignoresMetric || GetIsModelAcceptable(response))
                    {
                        UpdateModelInstance(response, sessionId);
                        SaveAcceptedSession(modelId, sessionId, response.ModelSummary);
                        _log.Info("\tModel was successfully trained. " +
                                  $"Instance uid: {modelSummary.ModelInstanceUId}, instance metric: {modelSummary.Metric}");
                    }
                    else
                    {
                        string message = "\tModel for schema {0} was successfully trained, but is not acceptable " +
                                         "to be applied. Instance uid: {1}, instance metric: {2}, metric threshold: {3}";
                        _log.WarnFormat(message, _modelConfig.Id, modelSummary.ModelInstanceUId, modelSummary.Metric,
                                        _modelConfig.MetricThreshold);
                        SaveUnacceptedSession(sessionId, modelSummary);
                    }
                } catch (Exception ex) {
                    UpdateModelOnError(modelId, ex.Message);
                    SaveFailedSession(sessionId, ex.Message);
                    throw;
                }
            }
            UpdateTrainSessionStatus(newSessionState, modelId, response.ErrorMessage);
            SaveTrainSession(_modelConfig.TrainSessionId, newSessionState, errorMessage: response.ErrorMessage);
        }
Example #5
0
        /// <summary>
        /// Updates the model instance.
        /// </summary>
        /// <param name="trainSessionInfo">The train session information.</param>
        /// <param name="trainSessionId">The train session identifier.</param>
        protected virtual void UpdateModelInstance(GetSessionInfoResponse trainSessionInfo, Guid trainSessionId)
        {
            ModelSummary modelSummary = trainSessionInfo.ModelSummary;

            modelSummary.CheckArgumentNull("ModelSummary");
            modelSummary.ModelInstanceUId.CheckArgumentEmpty("MLModelConfig.ModelSummary.ModelInstanceUId");
            Update updateQuery = (Update) new Update(_userConnection, "MLModel")
                                 .Set("ModelInstanceUId", Column.Parameter(modelSummary.ModelInstanceUId))
                                 .Set("InstanceMetric", Column.Parameter(modelSummary.Metric))
                                 .Set("TrainedOn", Column.Parameter(DateTime.UtcNow))
                                 .Where("TrainSessionId").IsEqual(Column.Parameter(trainSessionId));

            updateQuery.Execute();
        }
        private async Task CreateSession()
        {
            var session = await fixture.Client.Sessions.TrainModel(Sessions.TrainModel(fixture.ModelDataSetName, PredictionDomain.Regression, "instances"));

            while (true)
            {
                var status = await fixture.Client.Sessions.GetStatus(session.SessionId);

                if (status.Status == Status.Completed || status.Status == Status.Failed)
                {
                    break;
                }
                Thread.Sleep(5000);
            }
            var modelSession = await fixture.Client.Sessions.Get(session.SessionId);

            savedModel = await fixture.Client.Models.Get(modelSession.ModelId.Value);
        }
Example #7
0
        public void CreateModelSummary(Model m, IDatabase cache)
        {
            ModelSummary modelSummary = new ModelSummary()
            {
                ModelId = m.Id, ModelName = m.Name
            };
            decimal modelSummaryAmount = 0;

            foreach (ModelData d in cachingDemoContext.ModelData.Where(x => x.ModelId == m.Id))
            {
                var     thisAmount = d.Amount;
                decimal plusAmount = 0;
                if (d.PreviousId != null)
                {
                    plusAmount = cachingDemoContext.ModelData.Where(x => x.Id == d.PreviousId).First().Amount;
                }

                modelSummaryAmount += thisAmount + plusAmount;
            }

            modelSummary.ModelValue = modelSummaryAmount;
            cache.StringSet(MODELKEYNAME + m.Id, JsonConvert.SerializeObject(modelSummary));
        }
        private void Add(ModelSummary data)
        {
            Models[Path.GetFileName(data.FileName).ToUpper()]   = data;

            OnDataAdded(new DataFileEventArgs(data));
        }
        private void CloneModelFile(ModelSummary file, string newname)
        {
            var clone       = ModelFile.FromFile(file.FileName);
            clone.FileName  = newname;

            ReplaceDescription(clone.Descriptions);

            foreach(var i in clone.Materials)
                i.Descriptions[0]   = Replacer.ReplaceFileName(i.Descriptions[0]);

            foreach(var i in clone.Materials.SelectMany(j => j.Params).OfType<ParamTex>())
            {
                if(null != i.TexName)
                    i.TexName  = Replacer.ReplaceFileName(i.TexName);

                if(null != i.TexName)
                    i.TexAsset  = Replacer.ReplaceFileName(i.TexAsset);
            }

            if(ConfirmOverride(clone.FileName) == DialogResult.Yes)
            {
                ModelFile.ToFile(clone.FileName, clone);
                AddCopiedFile(clone);
            }
        }
Example #10
0
        /// <summary>
        /// Destruye todo el modelo y lo deja limpio
        /// </summary>
        /// <TODO>Modified, Save, Load</TODO>
        public void Reset()
        {
            try
            {
                this.undoManager = new UndoManager(this);
                undoManager.Enabled = false;
                this.abstractCases = new ManagedList<Canguro.Model.Load.AbstractCase>();
                abstractCases.ElementRemoved += new ManagedList<AbstractCase>.ListChangedEventHandler(abstractCases_ElementRemoved);
                this.activeLoadCase = null;
                this.areaList = new ItemList<AreaElement>();
                this.constraintList = new ManagedList<Constraint>();
                this.isLocked = false;
                this.jointList = new ItemList<Joint>();
                this.layers = new ItemList<Layer>();
                layers.ElementRemoved += new ManagedList<Layer>.ListChangedEventHandler(layers_ElementRemoved);
                this.lineList = new ItemList<LineElement>();
                this.loadCases = new ManagedDictionary<string, LoadCase>();
                loadCases.ElementRemoved += new ManagedDictionary<string, LoadCase>.ListChangedEventHandler(loadCases_ElementRemoved);
                this.summary = new ModelSummary(this);

                this.designOptions = new List<DesignOptions>();
                designOptions.Add(NoDesign.Instance);
                designOptions.Add(new LRFD99());
                designOptions.Add(new ACI318_02());
                designOptions.Add(new ASD01());
                designOptions.Add(new RCDF2001());
                designOptions.Add(new UBC97_ASD());
                designOptions.Add(new UBC97_LRFD());
                designOptions.Add(new UBC97_Conc());
                steelDesignOptions = NoDesign.Instance;
                concreteDesignOptions = NoDesign.Instance;
                coldFormedDesignOptions = NoDesign.Instance;
                aluminumDesignOptions = NoDesign.Instance;

                this.results = new Canguro.Model.Results.Results(0);

                // Layer es un Item y todos los Items asignan su propiedad layer
                // de acuerdo a ActiveLayer, por lo que hay que asignarla en null
                // antes de crear el primer Layer, root de todos los demás
                activeLayer = null;
                Layer rootLayer = new Layer(Culture.Get("defaultLayerName"));
                ActiveLayer = rootLayer;

                activeLoadCase = new LoadCase(Culture.Get("defaultLoadCase"), LoadCase.LoadCaseType.Dead);
                activeLoadCase.SelfWeight = 1.0f;
                loadCases.Add(activeLoadCase.Name, activeLoadCase);

                AnalysisCase anc = new Canguro.Model.Load.AnalysisCase(Culture.Get("defaultLoadCase"));
                AbstractCases.Add(anc);
                if (anc != null)
                {
                    StaticCaseProps props = anc.Properties as StaticCaseProps;
                    if (props != null)
                    {
                        List<StaticCaseFactor> list = props.Loads;
                        list.Add(new StaticCaseFactor(ActiveLoadCase));
                        props.Loads = list;
                    }
                }

                MaterialManager.Instance.Initialize();
                SectionManager.Instance.Initialize(ref sections);
                sections.ElementRemoved += new Catalog<Canguro.Model.Section.Section>.ListChangedEventHandler(sections_ElementRemoved);
                this.currentPath = "";
                foreach (Canguro.Model.UnitSystem.UnitSystem us in UnitSystemsManager.Instance.UnitSystems)
                    if (Properties.Settings.Default.UnitSystem.Equals(us.GetType().Name))
                        UnitSystemsManager.Instance.CurrentSystem = us;

                viewManager = Canguro.View.GraphicViewManager.Instance;
                modified = false;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                throw e;
            }
            finally
            {
                if (ModelReset != null)
                    ModelReset(this, EventArgs.Empty);
                undoManager.Enabled = true;
            }
        }
Example #11
0
 private void SaveUnacceptedSession(Guid trainSessionId, ModelSummary modelSummary)
 {
     SaveTrainSession(trainSessionId, TrainSessionState.Done, false, modelSummary);
 }