Comments (9)
Things that are not saved properly are:
location of cell, cell of individual and so on, so attributes that are not part of a process yet. Maybe this is solving itself if they become part of processes!
from pycopancore.
the question is now more: is this a bug? Do we need iterating through all variables? If they don't change, do we need their information? Or is it enough to get the information once, not every time a discontinuity is called?
from pycopancore.
Code proposal:
for (v, oc) in self.ODE_variables, self.explicit_variables, self.step_variables, self.event_variables:
entities = oc.entities
values = v.get_value_list(entities)
for i in range(len(entities)):
entity = entities[i]
value = np.array([values[i]])
try:
trajectory_dict[v][entity] = np.concatenate((
trajectory_dict[v][entity], value))
except KeyError:
trajectory_dict[v][entity] = value
t_np = np.array([t])
trajectory_dict['t'] = np.concatenate((trajectory_dict['t'], t_np))
So the first line has changed from self.model.variables to the variables that change. Now, after finishing the while loop, do following:
for (v,oc) in self.model.variables and not in self.ODE_variables, self.explicit_variables, self.step_variables, self.event_variables:
entities = oc.entities
values = v.get_value_list(entities)
for i in range(len(entities)):
entity = entities[i]
value = np.array([values[i]])
try:
trajectory_dict[v][entity] = np.concatenate((
trajectory_dict[v][entity], value))
except KeyError:
trajectory_dict[v][entity] = value
return trajectory_dict
Maybe there are some errors, but this is the idea
from pycopancore.
I agree with you.The code proposal also make sense since the performance will be better.
from pycopancore.
To make it easier to implement further processes in a later stage it might does make sense to reintroduce the process_variables in model.py.
from pycopancore.
Just a small proposal:
Instead of
for i in range(len(things)):
thing = things[i]
...
you could use
for i, thing in enumerate(things):
...
from pycopancore.
Thank you! Just changed it.
from pycopancore.
While we are at that, two more comments (:
(1) maybe simply use zip
(2) Usually it's good to avoid try except staements in Python, following the Zen of Python's (PEP20) "Explicit is better than implicit."
maybe simple use:
for entity, value in zip(entities, values):
if entity in trajectory[v]:
trajectory_dict[v][entity] = np.concatenate((
trajectory_dict[v][entity], value))
else:
trajectory_dict[v][entity] = np.array([value])
It shortens the whole thing and makes it directly readable.
from pycopancore.
Yes, I think it makes sense to change this, I put that suggestions into a separate issue #52 that only concerns code enhancement/improvement .
Since the main problem of this issue is already solved I closed it.
from pycopancore.
Related Issues (20)
- [generic_imitation] Dosed contagion
- streamline documentation across branches HOT 1
- create status checks
- lpjml coupling HOT 2
- provide Culture.individuals
- Error message when not giving initial values HOT 1
- provide group entity HOT 1
- Possible solution to PYTHONPATH problem
- two culture setters for world
- review tutorial model configuration
- Adjust Templates and Tutorial for new group entity
- Improve process documentation
- provide way so save (adaptive) networks
- profile code
- provide best-practice in performance questions
- Some units for Variable don't work HOT 4
- Give process taxa a UID
- patch Model.__init__ (taxa instantiation for mc runs)
- collections.MutableSet replaced by collections.abc.MutableSet
- consider Cython support?
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 pycopancore.