def get_tile(self, out_size, in_size, **kwargs): resistive_device = VectorUnitCell([ ConstantStepResistiveDeviceParameters(w_max_dtod=0, w_min_dtod=0), ConstantStepResistiveDeviceParameters(w_max_dtod=0, w_min_dtod=0), ]) return AnalogTile(out_size, in_size, resistive_device, **kwargs).cuda()
def test_save_load_meta_parameter(self): """Test saving and loading a device with custom parameters.""" params_devices = ConstantStepResistiveDeviceParameters(w_max=0.987) params_forward = AnalogTileInputOutputParameters(inp_noise=0.321) params_backward = AnalogTileBackwardInputOutputParameters( inp_noise=0.456) params_update = AnalogTileUpdateParameters(desired_bl=78) # Create the device and the array. resistive_device = ConstantStepResistiveDevice(params_devices, params_forward, params_backward, params_update) model = self.get_model(resistive_device=resistive_device) # Save the model to a file. file = TemporaryFile() save(model, file) # Load the model. file.seek(0) new_model = load(file) file.close() # Assert over the new model tile parameters. parameters = new_model.analog_tile.tile.get_parameters() self.assertAlmostEqual(parameters.forward_io.inp_noise, 0.321) self.assertAlmostEqual(parameters.backward_io.inp_noise, 0.456) self.assertAlmostEqual(parameters.update.desired_bl, 78)
def get_tile(self, out_size, in_size, device_params=None): """Return an analog tile of the specified dimensions.""" device_params = device_params or ConstantStepResistiveDeviceParameters( ) resistive_device = ConstantStepResistiveDevice( params_devices=device_params) python_tile = AnalogTile(out_size, in_size, resistive_device) self.set_init_weights(python_tile) return python_tile
def get_layer(self, cols=3, rows=4, **kwargs): """Return a layer.""" # pylint: disable=arguments-differ return AnalogLinear(cols, rows, resistive_device=ConstantStepResistiveDevice( ConstantStepResistiveDeviceParameters( w_max_dtod=0, w_min_dtod=0)), **kwargs).cuda()
def get_layer(self, in_channels=2, out_channels=3, kernel_size=4, **kwargs): """Return a layer.""" # pylint: disable=arguments-differ return AnalogConv2d(in_channels, out_channels, kernel_size, resistive_device=ConstantStepResistiveDevice( ConstantStepResistiveDeviceParameters( w_max_dtod=0, w_min_dtod=0)), **kwargs).cuda()
def test_device_parameter_constructor(self): """Test creating a device using parameters in the constructor.""" params_devices = ConstantStepResistiveDeviceParameters(w_max=0.987) params_forward = AnalogTileInputOutputParameters(inp_noise=0.321) params_backward = AnalogTileBackwardInputOutputParameters( inp_noise=0.456) params_update = AnalogTileUpdateParameters(desired_bl=78) # Create the device and the array. resistive_device = ConstantStepResistiveDevice(params_devices, params_forward, params_backward, params_update) analog_tile = resistive_device.create_tile(10, 20) # Assert over the parameters in the binding objects. parameters = analog_tile.get_parameters() self.assertAlmostEqual(parameters.forward_io.inp_noise, 0.321) self.assertAlmostEqual(parameters.backward_io.inp_noise, 0.456) self.assertAlmostEqual(parameters.update.desired_bl, 78)
def get_tile(self, out_size, in_size): """Return a tile of the specified dimensions with noisiness turned off.""" params = ConstantStepResistiveDeviceParameters() io_params = AnalogTileInputOutputParameters(is_perfect=True) io_params_backward = AnalogTileBackwardInputOutputParameters( is_perfect=True) up_params = AnalogTileUpdateParameters(pulse_type=PulseType('None')) resistive_device = ConstantStepResistiveDevice( params_devices=params, params_forward=io_params, params_backward=io_params_backward, params_update=up_params) python_tile = NumpyAnalogTile(out_size, in_size, resistive_device) # Set weights. init_weights = uniform(-0.5, 0.5, size=(python_tile.out_size, python_tile.in_size)) python_tile.set_weights(from_numpy(init_weights)) return python_tile
def get_device_params(self, **kwargs): """Return the default device params""" return ConstantStepResistiveDeviceParameters(**kwargs)
def get_tile(self, out_size, in_size, **kwargs): resistive_device = DifferenceUnitCell( ConstantStepResistiveDeviceParameters(w_max_dtod=0, w_min_dtod=0)) return AnalogTile(out_size, in_size, resistive_device, **kwargs)