Skip to content

Commit

Permalink
Fixed compare_simplified.
Browse files Browse the repository at this point in the history
It was bugged since the introduction of functional_unit
  • Loading branch information
raphaeljolivet committed Dec 9, 2024
1 parent a1313d2 commit ff4134f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
6 changes: 5 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#
* Fix bug in compare_simplified introduced since the release of *functional_unit*


# 1.1.2

Bugfix release :
* Fix major bug #58 with axis being in diffrent order when used with multiple methods
* Fix major bug #58 with axis being in different order when used with multiple methods
* Fix bug #54 : unexpected behaviour with '*' wildcard and 'old_amount' parameter

# 1.1
Expand Down
14 changes: 7 additions & 7 deletions doc/source/notebooks/init.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import pandas as pd
import time
import matplotlib.pyplot as plt
import numpy as np

import brightway2 as bw
import bw2data
import bw2io
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import SALib
from tabulate import tabulate
from sympy import *
from scipy.stats import binned_statistic
import seaborn as sns
from IPython.display import HTML, display
from scipy.stats import binned_statistic
from sympy import *
from tabulate import tabulate

# +
# Custom utils defined for inter-acv
Expand All @@ -21,7 +22,6 @@
# from lca_algebraic.stats import _generate_random_params, _compute_stochastics
# -

from IPython.display import HTML, display

# Larger space in notebook for large graphs
display(HTML("<style>.container { width:70% !important; }</style>"))
Expand Down
9 changes: 6 additions & 3 deletions lca_algebraic/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,10 @@ def _stochastics(
return problem, params, Y


def _compute_stochastics(modelOrLambdas, methods, functional_unit=1, params=dict()):
def _compute_stochastics(modelOrLambdas, methods, functional_unit=1, params=None):
if params is None:
params = {}

if isinstance(modelOrLambdas, Activity):
Y = compute_impacts(modelOrLambdas, methods, functional_unit=functional_unit, **params)
else:
Expand Down Expand Up @@ -1292,11 +1295,11 @@ def compare_simplified(
params, _ = _generate_random_params(100000, sample_method=StochasticMethod.RAND)

# Run Monte Carlo on full model
Y1 = _compute_stochastics([lambd], [method], params)
Y1 = _compute_stochastics([lambd], [method], params=params)
d1 = Y1[Y1.columns[0]]

# Run monte carlo of simplified model
Y2 = _compute_stochastics([simpl_lambd], [method], params)
Y2 = _compute_stochastics([simpl_lambd], [method], params=params)
d2 = Y2[Y2.columns[0]]

r_value = r_squared(Y1, Y2)
Expand Down

0 comments on commit ff4134f

Please sign in to comment.