custom_ml_surrogate_model
Module Contents
Classes
The |
|
The |
- class custom_ml_surrogate_model.CdModel(*args, **kwargs)
Bases:
csdl.CustomExplicitOperationThe
Nodeclass is a base type for nodes in a Directed Acyclic Graph (DAG) that represents the computation to be performed during model evaluation.- compute(inputs, outputs)
Define outputs as an explicit function of the inputs
Example
```py def compute(self, inputs, outputs):
outputs[‘L’] = 1/2 * inputs[‘Cl’] * inputs[‘rho’] * inputs[‘V’]**2 * inputs[‘S’] outputs[‘D’] = 1/2 * inputs[‘Cd’] * inputs[‘rho’] * inputs[‘V’]**2 * inputs[‘S’]
- compute_derivatives(inputs, derivatives)
User defined method to compute partial derivatives for this operation
Example
```py def compute(self, inputs, outputs):
outputs[‘L’] = 1/2 * inputs[‘Cl’] * inputs[‘rho’] * inputs[‘V’]**2 * inputs[‘S’] outputs[‘D’] = 1/2 * inputs[‘Cd’] * inputs[‘rho’] * inputs[‘V’]**2 * inputs[‘S’]
- def compute_derivatives(self, inputs, derivatives):
derivatives[‘L’, ‘Cl’] = 1/2 * inputs[‘rho’] * inputs[‘V’]**2 * inputs[‘S’] derivatives[‘L’, ‘rho’] = 1/2 * inputs[‘Cl’] * inputs[‘V’]**2 * inputs[‘S’] derivatives[‘L’, ‘V’] = inputs[‘Cl’] * inputs[‘rho’] * inputs[‘V’] * inputs[‘S’] derivatives[‘L’, ‘S’] = 1/2 * inputs[‘Cl’] * inputs[‘rho’] * inputs[‘V’]**2
derivatives[‘D’, ‘Cd’] = 1/2 * inputs[‘rho’] * inputs[‘V’]**2 * inputs[‘S’] derivatives[‘D’, ‘rho’] = 1/2 * inputs[‘Cd’] * inputs[‘V’]**2 * inputs[‘S’] derivatives[‘D’, ‘V’] = inputs[‘Cd’] * inputs[‘rho’] * inputs[‘V’] * inputs[‘S’] derivatives[‘D’, ‘S’] = 1/2 * inputs[‘Cd’] * inputs[‘rho’] * inputs[‘V’]**2
- define()
User defined method to define custom operation
Example
def define(self): self.add_input('Cl') self.add_input('Cd') self.add_input('rho') self.add_input('V') self.add_input('S') self.add_output('L') self.add_output('D') # declare derivatives of all outputs wrt all inputs self.declare_derivatives('*', '*'))
- initialize()
User defined method to declare parameter values. Parameters are compile time constants (neither inputs nor outputs to the model) and cannot be updated at runtime. Parameters are intended to make a
CustomOperationsubclass definition generic, and therefore reusable. The example below shows how aCustomOperationsubclass definition uses parameters and how the user can set parameters when constructing the exampleCustomOperationsubclass. Note that the user never instantiates nor inherits directly from theCustomOperationbase class.Example
```py # in this example, we inherit from ExplicitOperation, but # the user can also inherit from ImplicitOperation class Example(ExplicitOperation):
- def initialize(self):
self.parameters.declare(‘in_name’, types=str) self.parameters.declare(‘out_name’, types=str)
- def define(self):
# use parameters declared in
initializein_name = self.parameters[‘in_name’] out_name = self.parameters[‘out_name’]self.add_input(in_name) self.add_output(out_name) self.declare_derivatives(out_name, in_name)
# define run time behavior by defining other methods…
# compile using Simulator imported from back end… sim = Simulator(
- Example(
in_name=’x’, out_name=’y’,
),
)
- class custom_ml_surrogate_model.ClModel(*args, **kwargs)
Bases:
csdl.CustomExplicitOperationThe
Nodeclass is a base type for nodes in a Directed Acyclic Graph (DAG) that represents the computation to be performed during model evaluation.- compute(inputs, outputs)
Define outputs as an explicit function of the inputs
Example
```py def compute(self, inputs, outputs):
outputs[‘L’] = 1/2 * inputs[‘Cl’] * inputs[‘rho’] * inputs[‘V’]**2 * inputs[‘S’] outputs[‘D’] = 1/2 * inputs[‘Cd’] * inputs[‘rho’] * inputs[‘V’]**2 * inputs[‘S’]
- compute_derivatives(inputs, derivatives)
User defined method to compute partial derivatives for this operation
Example
```py def compute(self, inputs, outputs):
outputs[‘L’] = 1/2 * inputs[‘Cl’] * inputs[‘rho’] * inputs[‘V’]**2 * inputs[‘S’] outputs[‘D’] = 1/2 * inputs[‘Cd’] * inputs[‘rho’] * inputs[‘V’]**2 * inputs[‘S’]
- def compute_derivatives(self, inputs, derivatives):
derivatives[‘L’, ‘Cl’] = 1/2 * inputs[‘rho’] * inputs[‘V’]**2 * inputs[‘S’] derivatives[‘L’, ‘rho’] = 1/2 * inputs[‘Cl’] * inputs[‘V’]**2 * inputs[‘S’] derivatives[‘L’, ‘V’] = inputs[‘Cl’] * inputs[‘rho’] * inputs[‘V’] * inputs[‘S’] derivatives[‘L’, ‘S’] = 1/2 * inputs[‘Cl’] * inputs[‘rho’] * inputs[‘V’]**2
derivatives[‘D’, ‘Cd’] = 1/2 * inputs[‘rho’] * inputs[‘V’]**2 * inputs[‘S’] derivatives[‘D’, ‘rho’] = 1/2 * inputs[‘Cd’] * inputs[‘V’]**2 * inputs[‘S’] derivatives[‘D’, ‘V’] = inputs[‘Cd’] * inputs[‘rho’] * inputs[‘V’] * inputs[‘S’] derivatives[‘D’, ‘S’] = 1/2 * inputs[‘Cd’] * inputs[‘rho’] * inputs[‘V’]**2
- define()
User defined method to define custom operation
Example
def define(self): self.add_input('Cl') self.add_input('Cd') self.add_input('rho') self.add_input('V') self.add_input('S') self.add_output('L') self.add_output('D') # declare derivatives of all outputs wrt all inputs self.declare_derivatives('*', '*'))
- initialize()
User defined method to declare parameter values. Parameters are compile time constants (neither inputs nor outputs to the model) and cannot be updated at runtime. Parameters are intended to make a
CustomOperationsubclass definition generic, and therefore reusable. The example below shows how aCustomOperationsubclass definition uses parameters and how the user can set parameters when constructing the exampleCustomOperationsubclass. Note that the user never instantiates nor inherits directly from theCustomOperationbase class.Example
```py # in this example, we inherit from ExplicitOperation, but # the user can also inherit from ImplicitOperation class Example(ExplicitOperation):
- def initialize(self):
self.parameters.declare(‘in_name’, types=str) self.parameters.declare(‘out_name’, types=str)
- def define(self):
# use parameters declared in
initializein_name = self.parameters[‘in_name’] out_name = self.parameters[‘out_name’]self.add_input(in_name) self.add_output(out_name) self.declare_derivatives(out_name, in_name)
# define run time behavior by defining other methods…
# compile using Simulator imported from back end… sim = Simulator(
- Example(
in_name=’x’, out_name=’y’,
),
)