InSEEDS conservation agriculture implementation - #16
Conversation
…e importing * or interface as I
…dualized entities, also using component/model class
…ructure and tests
jnnsbrr
left a comment
There was a problem hiding this comment.
Thanks @hannah-pra , @MaRimm31 and maybe @luaschwarz for checking 🙏
| prices = FaoProducerPrices() | ||
| self.fao_pft_prices = xr.open_dataset(prices.ensure(sim_path)) | ||
|
|
||
| def _load_fao_capital_stock(self): |
There was a problem hiding this comment.
@hannah-pra and @MaRimm31 I needed reasonable values for capital and depreciation and investment which are both needed to emulate maintenance costs. These are available via FAOSTAT
There was a problem hiding this comment.
Both are workarounds for now and could later be replaced.
| # CAPITAL UPDATE | ||
| # ========================================================================= | ||
|
|
||
| def _update_capital(self): |
There was a problem hiding this comment.
@hannah-pra and @MaRimm31 check the update_capital method. It assumes that investment only comes from profit, neglecting any external financing such as loans.
| return | ||
|
|
||
| # ----------------------------------------------------------------- | ||
| # Deselect practices until affordable |
There was a problem hiding this comment.
Assumes basically that if something is too expansive intermediate solutions might be chosen.
| # ----------------------------------------------------------------- | ||
| # Step 6: Run TPB decision logic | ||
| # ----------------------------------------------------------------- | ||
| self.behaviour.update() |
There was a problem hiding this comment.
@hannah-pra This is the TPB calculation inside update. If TPB indicates - should switch afterwards some consistency checks are done - if they pass, apply switch.
| self._decline_years = 0 | ||
|
|
||
| # ----------------------------------------------------------------- | ||
| # Snapshot current state for trend computation |
There was a problem hiding this comment.
@hannah-pra Memory dictionary to capture current state when switched - to calculate trend for attititude etc.
| # NEIGHBOUR COMPARISON METHODS | ||
| # ========================================================================= | ||
|
|
||
| def _most_promising_bundle(self): |
There was a problem hiding this comment.
@hannah-pra Check if this is reasonable. The point is, they have to have some form of system to decide to which system to switch. So my thought would be why not take the most successfull. Would also make sense in our narrative.
| confidence_years = getattr(self.agent, "confidence_years", 10) | ||
|
|
||
| for neighbour in self.agent.neighbourhood: | ||
| # How similar is neighbour? (bundle + crop similarity) |
There was a problem hiding this comment.
@hannah-pra so here we now weight in different forms of similarity - crops, bundle bould also confidence over longer observation time period - all determine the effect on the attitude.
| # TPB COMPONENT: SOCIAL NORM | ||
| # ========================================================================= | ||
|
|
||
| def _compute_social_norm(self, new_bundle): |
There was a problem hiding this comment.
@hannah-pra again also this has to weight in the similarity to be reasonable and include homogenity because this is a new dimension which opens here - diversity ...
| # TPB COMPONENT: PERCEIVED BEHAVIORAL CONTROL (PBC) | ||
| # ========================================================================= | ||
|
|
||
| def _compute_risk_factor(self): |
There was a problem hiding this comment.
This is something experimental ...
| # Volatility can add up to 50% more risk on top of base | ||
| return min(1.0, base_risk + (1 - base_risk) * volatility_risk * 0.5) | ||
|
|
||
| def _pbc_for_bundle(self, new_bundle): |
There was a problem hiding this comment.
@hannah-pra also this we should discuss if reasonable.
…tries -> global mean
…t switch_blocker to determine reason for not changed
…dd evaluation time for farmer analogously to strategy switch time - mainly to reduce computation time
…g, parameter updates, less focus on capital
Conservation Agriculture Realisation: Model Summary
The theoretical basis of the Conservation Agriculture (CA) realisation is contrased in the following with the Regenerative Tillage realisation. Both use Theory of Planned Behaviour (TPB; Ajzen 1991) as their decision framework. The CA realisation extends TPB with multi-practice decisions, trend-based learning, adaptive management, capital dynamics, and similarity-weighted social learning.
1. Overview
2. Shared Foundation: Theory of Planned Behaviour
Both realisations implement the TPB intention equation (Ajzen 1991):
I = (w_att × A + w_norm × SN) × PBC
where:
PBC enters multiplicatively. A farmer with positive attitude and supportive norms but low PBC (e.g. unaffordable transition) will not adopt. This captures the empirical finding that intention requires both motivation and perceived capability (Ajzen 1991).
3. Regenerative Tillage: Baseline Model
3.1 Decision structure
The farmer chooses between conventional tillage (0) and no-till (1). Decisions are re-evaluated at fixed intervals (
strategy_switch_duration), staggered randomly across agents to avoid synchronisation artefacts.3.2 Attitude
Attitude has two sources, weighted by
weight_own_landandweight_social_learning:Own-land experience: Compare current soil carbon and crop yield to the values stored at the time of the last switch. A sigmoid maps the relative change to (0, 1). This captures experiential learning but is sensitive to single-year noise.
Social learning: Compare own soil C and yield to the average of neighbours who use the other strategy. If neighbours using no-till outperform, attitude toward no-till increases. This follows a simple observational learning logic but does not weight neighbours by relevance.
3.3 Social norm
Proportion of neighbours using no-till. A sigmoid centred at 0.5 maps this to (0, 1): when more than half of neighbours use no-till, the norm favours adoption.
3.4 PBC
PBC is a heuristic variable:
There is no explicit economic or cost model. PBC loosely captures "adjustment difficulty" but is not grounded in economic constraints.
3.5 Limitations motivating the CA extension
4. Conservation Agriculture: Theoretical Extensions
4.1 Multi-practice bundle decisions
Conservation Agriculture requires the joint adoption of minimum soil disturbance, permanent soil cover, and crop rotation/diversification (Kassam et al. 2009). The CA model represents this as a combinatorial decision over three binary practices (tillage, cover crop, residue retention), yielding 8 possible bundles:
conventionalresidue_onlycover_crop_onlycover_residuenotill_onlynotill_residuenotill_coverfull_caThis captures that practices interact: no-till without residue cover exposes soil (see §4.11), and full CA requires all three simultaneously. Farmers do not merely toggle a single switch; they navigate a space of complementary and competing practices.
4.2 Trend-based learning
The Regenerative Tillage model compares current values to the previous year, making it susceptible to inter-annual climate variability. The CA model instead evaluates annual rates of change in soil carbon, root-zone moisture, and crop yield since the last practice switch:
This has several consequences:
min_observation_years(typically 3) before reconsidering. This reflects the empirical finding that CA benefits often take several years to materialise (Pittelkow et al. 2015).Performance is summarised as a weighted score across the three indicators (soil C, moisture, yield), with weights reflecting farmer priorities. This score is normalised to the local neighbourhood range (min–max scaling) to enable cross-farm comparison.
4.3 Bundle memory and bounded rationality
Farmers maintain a per-bundle memory recording the observed trends, duration, year of last update, and failure count for each of the 8 bundles they have tried. This allows them to draw on past experience when evaluating alternatives.
Memories decay after a configurable period (default: 30 years). This implements bounded rationality (Simon 1955): agents do not have perfect recall. Old experiences lose relevance as environmental conditions (climate, markets, technology) change. Once a memory expires, the farmer treats the bundle as unexplored, allowing re-evaluation under current conditions.
When evaluating a candidate bundle, the farmer's own-experience attitude is the remembered trend weighted by confidence (duration / confidence_years). Short experience → low confidence → attitude falls back toward neutral (0.5). This avoids strong beliefs from brief trials.
4.4 Target bundle selection
Before computing TPB, the farmer must identify a target bundle to evaluate. This is a two-stage process: neighbour imitation, then (if no better neighbour exists) random exploration.
Stage 1: Imitate best-performing neighbour
The farmer scans all neighbours and identifies those with higher performance scores (weighted combination of soil C, moisture, and yield trends). Among better-performing neighbours, the one with the largest performance gap is selected. The target bundle is then set to that neighbour's current practice bundle.
This implements observational learning (Bandura 1977): farmers adopt practices they observe working well for others. By selecting the best neighbour rather than a random better one, the model captures aspiration toward high performers.
If no neighbour outperforms the focal farmer, Stage 2 is triggered.
Stage 2: Random exploration (innovation diffusion)
When no neighbour is better, the farmer may still explore a new bundle with some probability. This captures innovation without social influence — the "pioneer" behaviour that seeds diffusion processes (Rogers 2003).
Exploration probability depends on:
confidence_years. This reflects that farmers with longer experience on their current bundle are more willing to experiment.The exploration probability is capped at 15% to prevent excessive randomness.
Bundle filtering
Not all bundles are valid exploration targets:
From the remaining valid bundles, one is selected uniformly at random.
No target → no switch
If neither neighbour imitation nor exploration yields a target bundle, no switch is proposed and TPB is set to 0. The farmer continues with the current bundle.
4.6 Similarity-weighted social learning
Social learning theory (Bandura 1977) predicts that individuals learn preferentially from models they perceive as similar and successful. The CA model implements this through three weighting dimensions:
Bundle similarity: fraction of practices that match between the focal farmer and the neighbour. A neighbour using (1,1,1) is more informative for evaluating (1,1,0) than a neighbour using (0,0,0). This reflects that practice-specific experience is more transferable between similar management systems.
Crop similarity: whether the neighbour grows the same dominant crop at a similar area share. Neighbours facing similar agronomic conditions provide more relevant information. This is a fast heuristic (argmax comparison) rather than a full portfolio distance.
Confidence weighting: the neighbour's duration on their current bundle modulates the reliability of their signal. A neighbour who has used a bundle for 10 years provides a more stable signal than one who switched last year.
The combined weight (similarity × confidence) determines each neighbour's contribution to the focal farmer's attitude. The total similarity is a configurable weighted average of bundle and crop similarity (default: 60% bundle, 40% crop).
In contrast, the Regenerative Tillage model groups neighbours by strategy (conventional vs no-till) and compares to the average of the other group, without weighting by relevance or experience.
4.7 Social norm with conformity pressure
The descriptive social norm (Cialdini et al. 1990) — "what others do" — is computed as the average total similarity (bundle + crop) to neighbours. A bundle that many similar neighbours use has a higher norm score.
On top of this, the model adds conformity pressure based on neighbourhood homogeneity. When most neighbours use the same bundle (low diversity of practices), conformity pressure is high:
This asymmetry reflects empirical findings that deviating from established local practices carries higher social cost than conforming (Cialdini & Goldstein 2004). In the farming context, this captures phenomena such as peer scepticism toward innovators, shared equipment and knowledge networks favouring the majority practice, and reduced social support for non-conformists.
Neighbourhood homogeneity is measured as 1 − (unique_bundles − 1) / N_neighbours. This means conformity pressure is strongest when all neighbours use the same bundle and weakest in diverse neighbourhoods.
The Regenerative Tillage model's social norm is simply the proportion of neighbours using no-till, without conformity pressure or similarity weighting.
4.8 Adaptive management and fallback
Adaptive management (Holling 1978; Walters 1986) treats management interventions as experiments: if outcomes deteriorate, the intervention should be revised. The CA model implements this through a fallback mechanism:
min_observation_years), the model tracks consecutive years where performance falls below the baseline score recorded at switch time.fallback_yearsconsecutive years (default: 5), the farmer reverts to the previous bundle.max_failurestimes (default: 2) are excluded from future exploration.Comparing against the baseline at switch time (rather than the previous year) avoids false positives from gradual trends and focuses on whether the switch itself led to improvement. The grace period allows time for transition effects (e.g. soil biology adjustment after no-till adoption) before evaluation begins.
Fallback bypasses TPB: it is an emergency response, not a planned behaviour change. TPB intention is set to 1.0 directly, ensuring the reversion occurs.
The Regenerative Tillage model has no fallback mechanism. Once switched, a farmer can only switch again after the next evaluation interval.
4.9 Capital dynamics and affordability
The Regenerative Tillage model has no economic dimension. The CA model introduces capital dynamics grounded in FAO data and standard capital accounting (OECD 2009; Jorgenson 1963):
Initial capital:
where NCS = Net Capital Stocks from FAO (country-specific). This provides a data-driven starting endowment.
Annual capital update:
where:
Only positive profit contributes to reinvestment; losses lead to capital decline through depreciation without offsetting investment.
Affordability constraints:
Residue economics: Residue retention has an opportunity cost (value of residue as feed or for sale). Retention level is constrained by the ratio of current capital to opportunity cost.
4.10 PBC as cost–capital relationship with risk aversion
PBC in the CA model is derived from the farmer's economic situation rather than a heuristic decay:
Cost factor: A hyperbolic function of cost relative to disposable capital:
where cost_impact = transition cost + annual direct cost increase, and disposable_capital = capital − min_capital. PBC approaches 0 as cost approaches disposable capital and approaches 1 when costs are negligible.
Risk aversion (Chavas & Holt 1996): composed of two terms:
High risk → low PBC → lower adoption intention, even if attitude and norm are positive. This captures the empirical observation that risk is a key barrier to CA adoption in developing countries (Pannell et al. 2014).
4.11 Agronomic reasonableness filter
Some practice combinations are agronomically problematic. No-till without residue cover (bundles 4, 6) leaves soil unprotected against erosion, crusting, and temperature extremes. The model flags these bundles as unreasonable when residue opportunity cost is below a threshold (i.e. when retaining residue would be cheap). Unreasonable bundles are excluded from exploration and adoption.
This is not a hard constraint (when residue is expensive, these bundles are permitted) but a soft agronomic heuristic that prevents clearly counterproductive combinations.
4.12 Cover crop type selection
When cover crops are adopted, the type (legume vs non-legume) is determined from environmental conditions provided by LPJmL:
This links farmer decisions to biogeochemical feedbacks in the coupled model.
4.13 Agent functional types: pioneer vs traditionalist
Farmers are differentiated into two agent functional types (AFTs):
Pioneers adopt earlier, explore more, and tolerate more risk — corresponding to Rogers' "innovators" and "early adopters". Traditionalists require more evidence, are more risk-averse, and revert more easily — corresponding to "late majority" and "laggards".
Exploration probability is further modulated by:
4.14 Hysteresis: asymmetric switch/revert thresholds
The switch threshold for adopting a new bundle differs from the revert threshold for returning to a previous one (default: 0.5 vs 0.6). This asymmetry creates hysteresis: once adopted, a practice is retained even under moderate dissatisfaction. This prevents rapid oscillation and reflects the sunk-cost effect and learning investments associated with practice changes.
5. Decision Flow Summary
Each year, the CA farmer executes the following decision sequence:
6. File Structure
tillage_farmer.py: Regenerative Tillage realisation (single file, ~190 lines)ca_farmer.py: CA farmer agent — capital dynamics, FAO data, revenue, costs, practice applicationca_behaviour.py: TPB decision model — bundles, memory, social learning, social norm, PBC, fallback, explorationReferences