Coder Social home page Coder Social logo

Comments (3)

NoobIamNoob avatar NoobIamNoob commented on April 28, 2024 1

I found a quick fix solution :

1 - at the begining of your srcipt you import the Ok class :

from ax.utils.common.result import Ok

2 - In your custom metric class, for the fetch_trial_data function, you return the Ok object initialized with your Data. In my case the fetch_trial_data function looks like this now :

def fetch_trial_data(self, trial, **kwargs):
    records = []
    for arm_name, arm in trial.arms_by_name.items():
        # Extracting the result from trial metadata
        result = retrieve_result(trial.index, arm_name, self.result_directory)

        records.append({
            "arm_name": arm_name,
            "metric_name": self.name,
            "mean": result,
            "sem": 0.0,  # Standard error of the mean
            "trial_index": trial.index,
        })
    data = Data(df=pd.DataFrame.from_records(records))
    return Ok(data)

Good afternoon a-rouxel!

I don't know how it works but, It perfectly worked!
Thank you for your help!
Have a good day today! : )

I added

from ax.utils.common.result import Ok
and
for arm_name, arm in trial.arms_by_name.items():
in the metric function

for calling the AX functions
##Call AX functions 
from ax import (
    ComparisonOp,
    ParameterType,
    RangeParameter,
    ChoiceParameter,
    FixedParameter,
    SearchSpace,
    Experiment,
    OutcomeConstraint,
    OrderConstraint,
    SumConstraint,
    OptimizationConfig,
    Objective,
    Metric,
    Data
)
from ax.utils.notebook.plotting import render, init_notebook_plotting

init_notebook_plotting()
from ax.utils.common.result import Ok #I added this part

for metric function,

#Create Metric
from ax import Metric
import pandas as pd

class Discrep_Metric(Metric):
    def fetch_trial_data(self, trial):
    
        records = []

        for arm_name, arm in trial.arms_by_name.items():        
       
            #Call MSE calculation that is defined from global env   
            mse = MSE_CALCULATION() 

            # Record
            records.append({
                "arm_name": arm_name,
                "metric_name": self.name,
                "mean": mse,  # MSE 값
                "sem": 0.0, 
                "trial_index": trial.index,
            })
            
        data = Data(df=pd.DataFrame.from_records(records))
        return Ok(data)

from ax.

a-rouxel avatar a-rouxel commented on April 28, 2024

I have the same issue here. In the docs, the fetch_trial_data function from the Custom metric should return a Data object, however, in the base function from the metric.py file, it is indicated that it should return a MetricFetchResult object that is defined like this : Result[Data, MetricFetchE] .... There is something wrong here but i am not sure how to fix it. I'll keep you updated if i find a good solution !

from ax.

a-rouxel avatar a-rouxel commented on April 28, 2024

I found a quick fix solution :

1 - at the begining of your srcipt you import the Ok class :

from ax.utils.common.result import Ok

2 - In your custom metric class, for the fetch_trial_data function, you return the Ok object initialized with your Data.
In my case the fetch_trial_data function looks like this now :

def fetch_trial_data(self, trial, **kwargs):
    records = []
    for arm_name, arm in trial.arms_by_name.items():
        # Extracting the result from trial metadata
        result = retrieve_result(trial.index, arm_name, self.result_directory)

        records.append({
            "arm_name": arm_name,
            "metric_name": self.name,
            "mean": result,
            "sem": 0.0,  # Standard error of the mean
            "trial_index": trial.index,
        })
    data = Data(df=pd.DataFrame.from_records(records))
    return Ok(data)

from ax.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.