愛記システム概念設計:個人の評価項目・愛の行動が偏りすぎない | 続・ティール組織 研究会のブログ

続・ティール組織 研究会のブログ

ティール組織が話題になっているが、具現化するにはどうしたらよいか?
その研究を続けるにあたり、さらに次の形態である、続・ティール組織なるものまで視野に入れ、具体的な施策・行動内容を研究・支援する会。

先までは、"愛記"についての記載で、どのようにブロックチェーンSNSに組み込んで実装していけばよいのか、概念的なところからアプローチ方法を記載していった。大まかな概念としてはひとまず終えた。次は、ブロックチェーンの概念設計といえるところまで、基本設計書に着手できるようなところまで、概念を具体化していきたい。

個人の評価項目について⑤

愛の行動の評価は何を規準に、どのようになされていくのであろうか。そこを記載したい。先に評価項目について記載した。評価を設計するに際し、コンピテンシーなる標準行動を考えていくべきなのであろう。この標準行動をとるような人が設計のモデルとなり、そこからどれほどバラつくかを設計していくことで良いのだろう。

・”ゆらぎ”件数:3件/月以上

・対象相手:偏りすぎないこと

・次元:偏りすぎないこと

・波動レベル:偏りすぎないこと

・愛の行動量:30回/月以上

 

これらの状態を見える化する、つまりはフィードバックすることがなによりも、落ちていることを自分に気づかせる手段なのであり、”愛記”により、一目瞭然となるのである!とても分かりやすいフィードバックであるので、自己理解ツールにもなり得るだろう。

◆波動レベルが偏りすぎない について

前回、”次元”について記載した。今回は波動レベルについて見てみよう。波動レベルは、下図のような意識レベル(チャクラ)・意志レベル(愛の行動)・ボディレベル(発達課題)の三位一体を考慮していくことで導き出せるのであった。3つのレベルの内、一番低いレベルに結局は合わさるようになるということであった。

そのうちの意識レベルとボディレベルは、なかなか数値計測は難しいので、今自分がどのレベルにいるのかが理解しにくいのであろう。一方、意志レベル(愛の行動)は、測定可能のため、ここを測定することで、擬似的に波動レベルを測定するということとしたい。

 

・DApps側であるPythonプログラム

では、愛の行動レベルが偏りすぎていないかどうかを評価するDApps側であるPythonプログラムを構築したい。例えば、DApps側で愛の行動レベル評価というボタンを押せば、現時点での愛の行動レベルの偏りを表示できるような仕組みにしたい。それには、4月1日~リクエスト現時点まで、何件の愛の行動を行っているのかの集計が必要だし、偏り評価を数学的なアルゴリズムで評価する仕組みも必要だろう。

 

なお、愛の行動レベルの難易度を考慮するアプローチのような場合、各レベルの難易度を定量化して、それに基づいて偏り評価を行うことができる。具体的には、各愛の行動に対して難易度係数を設定し、それを元に愛の行動件数を補正することが考えられる。例えば、レベル1が基準となる場合、レベル1の難易度係数を1とし、レベル10の難易度係数を10と設定する。そして、各生命体が行った愛の行動件数を、各愛の行動レベルの難易度係数で割って補正する。これにより、より高レベルの愛の行動がより重視されるようになる。ただし、このような難易度係数を設定する場合、どのような基準でそれぞれのレベルの難易度を定義するかが重要である。一般的な基準を設けることも考えられるが、システムの設計者が独自の基準を設定することもできる。

from collections import defaultdict

class LoveActionEvaluation:
    def __init__(self):
        self.love_actions = defaultdict(int)
        self.difficulty_coefficients = {
            1: 1,   # Level 1 is the baseline
            2: 2,
            3: 3,
            4: 4,
            5: 5,
            6: 6,
            7: 7,
            8: 8,
            9: 9,
            10: 10   # Level 10 has the highest difficulty coefficient
        }

    def add_action(self, level, count=1):
        self.love_actions[level] += count

    def evaluate(self):
        # Apply difficulty coefficients and calculate total actions
        adjusted_actions = {level: count / self.difficulty_coefficients[level] for level, count in self.love_actions.items()}
        total_actions = sum(adjusted_actions.values())

        # Calculate standard deviation from the average
        average_actions = total_actions / len(self.love_actions)
        variance = sum((count - average_actions) ** 2 for count in adjusted_actions.values()) / len(self.love_actions)
        std_deviation = variance ** 0.5

        # Check for imbalance
        imbalance_threshold = 1.5  # Adjust as needed
        is_imbalanced = std_deviation > imbalance_threshold

        return is_imbalanced, std_deviation, average_actions, self.love_actions

# Sample data
evaluation = LoveActionEvaluation()
evaluation.add_action(1, 10)
evaluation.add_action(2, 5)
evaluation.add_action(3, 3)
evaluation.add_action(4, 2)
evaluation.add_action(5, 1)
evaluation.add_action(6, 1)
evaluation.add_action(7, 1)
evaluation.add_action(8, 1)
evaluation.add_action(9, 1)
evaluation.add_action(10, 1)

# Evaluate love action imbalance
is_imbalanced, std_deviation, average_actions, love_actions = evaluation.evaluate()

# Display results
print("Love Action Levels:")
for level, count in love_actions.items():
    print(f"Level {level}: {count} actions")

print(f"\nAverage Actions per Level: {average_actions}")
print(f"Standard Deviation: {std_deviation}")
print(f"Is Imbalanced?: {is_imbalanced}")
 

このプログラムでは、各愛の行動レベルの難易度係数を設定し、各行動の総件数を難易度係数で補正している。最終的に、偏りの評価を行い、結果を出力している。

 

・DApps側と繋がるスマートコントラクトのプログラム

次に、Rustで市町村のブロックチェーンプラットフォームに接続するスマートコントラクトを開発しよう。まず、スマートコントラクトが行う基本的な機能を確認しよう。具体的には、ユーザーが愛の行動レベル評価ボタンを押すと、必要なデータを要求し、評価を行う機能を実装する。その後、ブロックチェーンにトランザクションを送信する方法を追加する。以下に、このスマートコントラクトの基本的な構造を示す:

use std::collections::HashMap;

struct LoveAction {
    level: u32,
    count: u32,
}

impl LoveAction {
    fn new(level: u32, count: u32) -> Self {
        LoveAction { level, count }
    }
}

struct LoveActionLevelEvaluation {
    actions: HashMap<u32, u32>, // Key: level, Value: count
    difficulty_coefficients: HashMap<u32, f64>, // Key: level, Value: coefficient
}

impl LoveActionLevelEvaluation {
    fn new() -> Self {
        let mut difficulty_coefficients = HashMap::new();
        difficulty_coefficients.insert(1, 1.0); // Level 1 as baseline

        LoveActionLevelEvaluation {
            actions: HashMap::new(),
            difficulty_coefficients,
        }
    }

    fn add_action(&mut self, level: u32, count: u32) {
        self.actions.insert(level, count);
    }

    fn evaluate_imbalance(&self) -> (bool, f64) {
        let total_actions: u32 = self.actions.values().sum();
        let num_levels = self.actions.len() as f64;
        let average_actions = total_actions as f64 / num_levels;

        let variance = self.actions.values().map(|&count| {
            let diff = (count as f64 - average_actions).powi(2);
            diff
        }).sum::<f64>() / num_levels;

        let std_deviation = variance.sqrt();

        let imbalance_threshold = 1.5; // Adjust as needed
        let is_imbalanced = std_deviation > imbalance_threshold;

        (is_imbalanced, std_deviation)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_add_action() {
        let mut evaluation = LoveActionLevelEvaluation::new();
        evaluation.add_action(1, 10);
        assert_eq!(evaluation.actions.get(&1), Some(&10));
    }

    // Add more tests as needed
}
このスマートコントラクトは、LoveActionLevelEvaluation構造体を介して愛の行動レベルの難易度を考慮した評価を行う。Pythonプログラムから送信された愛の行動データを受け取り、add_actionメソッドを使用して各レベルの行動件数を更新する。evaluate_imbalanceメソッドを呼び出すことで、偏りの評価を行い、結果を返す。

 

・市町村のブロックチェーンのrustのプログラム

なお、市町村のブロックチェーンのプログラムをrustに置き換えてやってみたので、以下に記す。この市町村のブロックチェーンのプログラムに上記のスマートコントラクトが実装され、DApps側であるPythonプログラムからスマートコントラクトが呼び出される度に、評価が実行されるという具合だ。
use chrono::{DateTime, Local};
use rand::{CryptoRng, Rng};
use sha2::{Digest, Sha256};
use std::collections::HashMap;

struct Wallet {
    address: String,
    balance: f64,
}

impl Wallet {
    fn new(address: &str) -> Self {
        Wallet {
            address: address.to_string(),
            balance: 0.0,
        }
    }

    fn add_balance(&mut self, amount: f64) {
        self.balance += amount;
    }

    fn subtract_balance(&mut self, amount: f64) -> Result<(), &'static str> {
        if self.balance >= amount {
            self.balance -= amount;
            Ok(())
        } else {
            Err("Insufficient balance")
        }
    }
}

struct Transaction {
    transaction_id: String,
    sender: String,
    receiver: String,
    timestamp: String,
    location: String,
    love_action_level: u32,
    amount: f64,
    action_content: String,
    approval_target: String,
    zero_knowledge_proof: Option<()>, // Placeholder for actual proof
    sender_dimension: u32,
    receiver_dimension: u32,
    validators: Vec<String>,
}

impl Transaction {
    fn new(
        sender: &str,
        receiver: &str,
        location: &str,
        love_action_level: u32,
        action_content: &str,
        sender_dimension: u32,
        receiver_dimension: u32,
        approver: &str,
        approver_dimension: u32,
    ) -> Self {
        Transaction {
            transaction_id: format!("{:x}", rand::random::<u128>()),
            sender: sender.to_string(),
            receiver: receiver.to_string(),
            timestamp: Local::now().to_string(),
            location: location.to_string(),
            love_action_level,
            amount: 0.0,
            action_content: action_content.to_string(),
            approval_target: approver.to_string(),
            zero_knowledge_proof: None,
            sender_dimension,
            receiver_dimension,
            validators: Vec::new(),
        }
    }

    fn generate_proof_of_place(&self) -> String {
        format!(
            "Transaction {}'s proof of place has been generated: {}",
            self.transaction_id, self.location
        )
    }

    fn generate_proof_of_history(&self) -> String {
        format!(
            "Transaction {}'s proof of history has been generated: {}",
            self.transaction_id, self.timestamp
        )
    }

    fn generate_zero_knowledge_proof(&mut self) {
        // Placeholder implementation
        self.zero_knowledge_proof = Some(());
    }

    fn transfer_token(&self, love_currency: &str) {
        println!(
            "Token transfer: {} token transferred from {} to {} in dimension {}.",
            love_currency, self.sender, self.receiver, self.receiver_dimension
        );
    }

    fn pay_reward_to_approver(&self, reward_amount: f64, wallets: &mut HashMap<String, Wallet>) {
        if let Some(approver_wallet) = wallets.get_mut(&self.approval_target) {
            approver_wallet.add_balance(reward_amount);
        }
    }
}

struct Block {
    index: u32,
    previous_hash: String,
    timestamp: String,
    data: String,
    proof_of_place: String,
    proof_of_history: String,
    zero_knowledge_proof: Option<()>, // Placeholder for actual proof
    hash: String,
}

impl Block {
    fn new(
        index: u32,
        previous_hash: &str,
        data: &str,
        proof_of_place: &str,
        proof_of_history: &str,
        zero_knowledge_proof: Option<()>,
    ) -> Self {
        Block {
            index,
            previous_hash: previous_hash.to_string(),
            timestamp: Local::now().to_string(),
            data: data.to_string(),
            proof_of_place: proof_of_place.to_string(),
            proof_of_history: proof_of_history.to_string(),
            zero_knowledge_proof,
            hash: String::new(), // Placeholder for actual hash
        }
    }

    fn calculate_hash(&mut self) {
        let hash_data = format!(
            "{}{}{}{}{}{}{}",
            self.index,
            self.previous_hash,
            self.timestamp,
            self.data,
            self.proof_of_place,
            self.proof_of_history,
            match &self.zero_knowledge_proof {
                Some(_) => "1",
                None => "0",
            }
        );
        let hash = Sha256::digest(hash_data.as_bytes());
        self.hash = format!("{:x}", hash);
    }
}

struct Blockchain {
    chain: Vec<Block>,
    validators: Vec<String>,
    current_validators: Vec<String>,
}

impl Blockchain {
    fn new() -> Self {
        Blockchain {
            chain: vec![Blockchain::create_genesis_block()],
            validators: Vec::new(),
            current_validators: Vec::new(),
        }
    }

    fn create_genesis_block() -> Block {
        Block::new(0, "0", "Genesis Block", "Proof of Place", "Proof of History", None)
    }

    fn get_latest_block(&self) -> Option<&Block> {
        self.chain.last()
    }

    fn add_validator(&mut self, validator: &str) {
        self.validators.push(validator.to_string());
    }

    fn select_validators(&mut self) -> Vec<String> {
        self.current_validators = rand::seq::index::sample(&mut rand::thread_rng(), &self.validators, 3).unwrap();
        self.current_validators.clone()
    }

    fn add_block(&mut self, transaction: Transaction) {
        let index = self.chain.len() as u32;
        let previous_block = self.get_latest_block().unwrap();
        let mut new_block = Block::new(
            index,
            &previous_block.hash,
            &transaction.action_content,
            &transaction.generate_proof_of_place(),
            &transaction.generate_proof_of_history(),
            transaction.zero_knowledge_proof,
        );
        new_block.calculate_hash();

        // Validate the block by current validators
        if transaction.validators.iter().all(|v| self.current_validators.contains(v)) {
            self.chain.push(new_block);
            transaction.pay_reward_to_approver(transaction.love_action_level as f64 * 0.03);
        } else {
            println!("Block validation failed. Block not added to the chain.");
        }
    }
}

fn main() {
    let mut blockchain = Blockchain::new();
    let mut wallets: HashMap<String, Wallet> = HashMap::new();

    // Create wallets for municipalities
    for municipality in &["Municipality1", "Municipality2", "Municipality3"] {
        wallets.insert(municipality.to_string(), Wallet::new(municipality));
    }

    let users = vec![
        ("A", "Location1", 8, 2, 4, "Action Content A"),
        ("B", "Location2", 6, 2, 3, "Action Content B"),
        ("C", "Location3", 3, 3, 4, "Action Content C"),
        ("D", "Location4", 10, 3, 2, "Action Content D"),
    ];

    let approvers = vec!["A", "B", "C", "D"];

    for (sender_name, location, love_action_level, sender_dimension, receiver_dimension, action_content) in &users {
        for (receiver_name, _, _, _, _, _) in &users {
            if sender_name != receiver_name {
                let approver_name = approvers.choose(&mut rand::thread_rng()).unwrap();
                let transaction = Transaction::new(
                    sender_name,
                    receiver_name,
                    location,
                    *love_action_level,
                    action_content,
                    *sender_dimension,
                    *receiver_dimension,
                    approver_name,
                    users.iter().find(|(name, _, _, _, _, _)| name == approver_name).unwrap().3,
                );
                let validators = blockchain.select_validators();
                let love_currency = TOKEN_TYPES.get(&transaction.love_action_level).unwrap_or(&"Unknown");
                transaction.transfer_token(love_currency);
                blockchain.add_block(transaction);
            }
        }
    }

    if let Some(latest_block) = blockchain.get_latest_block() {
        println!("Latest Block #{} - Hash: {}", latest_block.index, latest_block.hash);
    }
}
 

 

いかがであろうか、これで、愛の行動レベルの偏りという評価をすることができるようになった。これで擬似的に波動レベルの偏りを評価することができるようになった。これをユーザーが閲覧したいとリクエストする度に表示できるようになったことで、波動レベルの偏りを常にチェックできるということだ。