Comments (2)
I dug through the git history a bit and it looks like safe_squeeze()
was added in 97d5b23 and then removed in 9835e3f. Then safe_cast_to_array() was added in 3bc0374. It looks like the only difference is that safe_squeeze()
gave the option to specify the dtype
of the returned array, and ensured it was float
by default. I've copy/pasted the code for each function below for reference.
def safe_cast_to_array(in_array):
'''
Attempts to safely cast the input to an array. Takes care of border cases
Args:
in_array (array or equivalent): The array (or otherwise) to be converted to a list.
Returns:
array : array that has been squeezed and 0-D cases change to 1-D cases
'''
out_array = np.squeeze(np.array(in_array))
if out_array.shape == ():
out_array = np.array([out_array[()]])
return out_array
def safe_squeeze(in_array, set_dtype = float):
'''
Attempts to squeeze an array, but has a different behavior for arrays with only a single value.
Args:
in_array (array): The array to be squeezed
Returns:
array: Array.
'''
out_array = np.squeeze(np.array(in_array, dtype=set_dtype))
if out_array.shape == ():
out_array = np.array([out_array[()]])
return out_array
Experimentally I've tried monkey patching things to replace the calls to safe_squeeze()
with calls to safe_cast_to_array()
and things worked fine. Example code below (file names and types are set elsewhere):
import mloop.visualizations as mlv
# Monkey patch safe_cast_to_array() in place of safe_squeeze() in neural net visualizer code.
mlv.mlu.safe_squeeze = mlv.mlu.safe_cast_to_array
# Make the plots.
mlv.configure_plots()
mlv.create_controller_visualizations(controller_archive, file_type=file_type)
mlv.create_neural_net_learner_visualizations(learner_archive, file_type=file_type)
@michaelhush @charmasaur I can go ahead and replace the calls to safe_squeeze()
with calls to safe_cast_to_array()
and submit a pull request. Alternatively, I could add the code for safe_squeeze()
back in to utilities.py
.
from m-loop.
Thanks for the sleuthing! Migrating safe_squeeze()
calls to safe_cast_to_array()
sounds good to me.
(incidentally, the revert commit was when I accidentally merged some development work to master... I guess I must have messed something up, and accidentally also reverted some stuff that was already in master)
from m-loop.
Related Issues (20)
- Creating a learner visualizer instance creates an M-LOOP_archives directory HOT 1
- lanscape_vis.py is Outdated
- Syntax error during installation HOT 22
- Tests hang due to test_shell_interface_config()
- Update install instructions HOT 1
- test_gaussian_process_complete_config fails HOT 1
- Support for discrete parameter spaces HOT 5
- Error when computing predicted best parameters HOT 4
- Tutorial Code Bug for neural_net and gaussian_process Learners HOT 9
- `Controller` docstring has some incorrectly specified default values
- Simplify training archive arguments
- Include phrase "Bayesian Optimization" in the docs
- Default ANN - Possible to create custom ANN HOT 3
- Incompatible with latest numpy HOT 1
- Scikit-Learn `RuntimeError` due to `ParameterScaler` using `*args` HOT 1
- A typo in controllers.py HOT 2
- Program stop mid running without any outup HOT 1
- Problem importing previous training data when using gaussian process HOT 7
- GP possible overestimates uncertainty? HOT 4
- Some visualization method names and plot labels are misleading HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from m-loop.