Build and run complex models composed of formulas and data
Project description
Escape from spreadsheet models!
What is modelx?
modelx is a Python package for performing complex calculations by creating models composed of structured data and formulas written in the form of Python functions. You can think of it as a multidimensional version of spreadsheet, but it窶冱 so much more!
How modelx works
modelx exposes its API functions and classes such as Model, Space and Cells to its users, and the users build their models from those classes, by defining calculation formulas in the form of Python functions and associating those calculations with Cells objects.
Below is a very simple working example in which following operations are demonstrated:
a new model is created,
and in the model, a new space is created,
and in the space, a new cells is created , which is associated with the Fibonacci series.
from modelx import *
model, space = new_model(), new_space()
@defcells
def fibo(n):
if n == 0 or n == 1:
return n
else:
return fibo(n - 1) + fibo(n - 2)
To get a Fibonacci number for, say 10, you can do:
>>> fibo(10) 55 >>> fibo.series n 0 0 1 1 2 1 3 2 4 3 5 5 6 8 7 13 8 21 9 34 10 55 Name: fibo, dtype: int64
Feature highlights
You may not see the whole point of usig modelx as the example above is a simple one illustrating its fundamental mechanism, but modelx comes with features that enable users to build and manipulate more complex models in smart ways:
Cells containing formulas and data
Dynamic scoping for evaluating formulas
Cells graph to track cells interdependency
Spaces to organize cells by related calculations
Sub-spacing (having nested spaces within spaces)
Space inheritance
Dynamic parametrized spaces created automatically
Saving to / loading from files
Conversion to Pandas objects
Reading from Excel files
Who is modelx for?
modelx is designed to be domain agnostic. The modelx was created by an actuary to be used as a base tool to develop actuarial projection models, but it is intentionally designed to eliminate domain specific features so that potential audience for modelx can be anyone who needs to develop complex models of any sorts that are too much to deal with by spreadsheets.
Python and modelx
Aside from modelx being a Python package and written entirely in Python, modelx utilizes Python in that it lets users define formulas by writing Python functions and converting it to modelx formulas. However, there is a critical difference between how Python functions are interpreted by Python and how modelx formulas are interpreted by modelx.
Python employs lexical scoping, i.e. the namespace in which function code is executed is determined by textual context. The global namespace of a function is the module that the function is defined in. In contrast, the evaluation of modelx formulas is based on dynamic scoping. Each Cells belongs to a space, and the space has associated namespace (a mapping of names to objects). The formula associated with the cells is evaluated in that namespace. So, what module a formula is defined (in the form of a Python function) does not affect the result of formula evaluation. It is what space the cells belongs to that affects the result.
License
Copyright 2017-2018, Fumito Hamamura
modelx is free software; you can redistribute it and/or modify it under the terms of GNU Lesser General Public License v3 (LGPLv3).
Contributions, productive comments, requests and feedback from the community are always welcome. Information on modelx development is found at Github https://github.com/fumitoh/modelx
Development State
modelx is in its early alpha-release stage, and its specifications are subject to changes without consideration on backward compatibility. The source files of you models may need to be modified manually, if there are updates that break backward compatibility in newer versions of modelx.
Likewise, model files saved with one version may not load with a newer version. When updating modelx to a newer version, make sure you rebuild model files saved using older versions of modelx from their source code.
History
modelx was originally conceived and written by Fumito Hamamura and it was first released in October 2017.
Requirements
Python 3.6+
NetwrkX 2.0+
Pandas
OpenPyXL
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file modelx-0.0.16.tar.gz
.
File metadata
- Download URL: modelx-0.0.16.tar.gz
- Upload date:
- Size: 80.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93845affd6eb2069da5d03e4454e07f988317a7d4d2ab22182bfd23497868935 |
|
MD5 | 0b4fd39e620976b1c18b6a7fddc246d3 |
|
BLAKE2b-256 | a7bc047bd26bd355fc67b321c1ac5bb1127974197fa8aece55741510c209d5a9 |
File details
Details for the file modelx-0.0.16-py3-none-any.whl
.
File metadata
- Download URL: modelx-0.0.16-py3-none-any.whl
- Upload date:
- Size: 94.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11a61694450fa796870d1d127bbf017172db88288ba48e23b7229d81b6083e25 |
|
MD5 | 85f9d46fba35b3288adb3156cdf125fd |
|
BLAKE2b-256 | 8f57cfbcc5752f701ecf65628fd4a39b00334fe359ba74735c4fa80eab6fe780 |