<-->

hopfield

 

import numpy as np
from PIL import Image
import os

# 모델 로드
data = np.load('model.npz')
W = data['W']  # (N, N)
v0 = data['v0']  # (N, N)
N = W.shape[0]

def analyze_hopfield_weights(W):
    # Perform eigen decomposition
    eigenvalues, eigenvectors = np.linalg.eigh(W)
    
    # Threshold eigenvectors to recover patterns
    recovered_patterns = np.sign(eigenvectors)

    
    return recovered_patterns, eigenvalues, eigenvectors

def recover_patterns_from_eigenvectors(eigenvalues, eigenvectors, threshold=0):
    # Select eigenvectors with eigenvalues greater than the threshold
    significant_indices = np.where(eigenvalues > threshold)[0]
    significant_eigenvectors = eigenvectors[:, significant_indices]
    
    # Binarize (threshold) the eigenvectors to obtain patterns
    recovered_patterns = np.sign(significant_eigenvectors)
    
    return recovered_patterns.T 

def pattern_to_image(pattern, image_shape):
    # Map -1, 1 to 0, 255
    image = (pattern + 1) * 127.5  # -1 -> 0, +1 -> 255
    image = image.reshape(image_shape).astype(np.uint8)
    return image

def save_pattern_as_image(pattern, image_shape, file_path):
    # Map -1, 1 to 0, 255 and reshape
    image = (pattern + 1) * 127.5  # -1 -> 0, +1 -> 255
    image = image.reshape(image_shape).astype(np.uint8)
    
    # Convert to PIL Image and save
    img = Image.fromarray(image)
    img.save(file_path)

recovered_patterns, eigenvalues, eigenvectors = analyze_hopfield_weights(W)
recovered_patterns = recover_patterns_from_eigenvectors(eigenvalues, eigenvectors)
os.makedirs("gggg", exist_ok=True)
for i in range(len(recovered_patterns)):
    save_pattern_as_image(recovered_patterns[i], (10, 120), "gggg/" + str(i) + ".png")

 

 


Silly Project #1

 

1. change first stdin

2. re-proof that

 

use base64::Engine;
use sp1_sdk::ProverClient;
use std::fs::File;
use std::io::Write;

pub const ELF: &[u8] = include_bytes!("../../../elf/silly-project-1-program");

fn main() {
    let client = ProverClient::new();
    let (pk, vk) = client.setup(ELF);
    println!("Prove it!");
    let mut proof: sp1_sdk::SP1ProofWithPublicValues = bincode::deserialize(
        &base64::prelude::BASE64_STANDARD
            .decode(
                &std::io::stdin()
                    .lines()
                    .next()
                    .expect("No line")
                    .expect("No line")[..],
            )
            .expect("base64"),
    )
    .expect("Proof format");
    proof.stdin.buffer[0][0] = 1;
    let mut my_proof= client.prove(&pk, proof.stdin.clone()).run();
    my_proof.unwrap().save("mymy.proof");
}

 

'writeups' 카테고리의 다른 글

hxp 38C3 CTF - respectable_nft  (0) 2024.12.30
2024 Blaz CTF - solana challs  (0) 2024.10.08
2024 codegate - sms  (0) 2024.09.04
SekaiCTF 2024 - solana  (0) 2024.08.26
CrewCTF 2024 - blockchain(lightbook)  (0) 2024.08.05

+ Recent posts