Bootstrap 5 Tutorials

W3SCHOOLS
https://www.w3schools.com/bootstrap5/index.php

• Grids
https://www.w3schools.com/bootstrap5/bootstrap_grid_basic.php

Bootstrap 5 Design Resources

• https://github.com/jqueryscript/Bootstrap-5-Design-Resources

Bootstrap 5 Lightboxes

Some of the best free options
• Lightbox for Bootstrap 5 (a.k.a. bs5-lightbox): This is a pure JavaScript lightbox gallery plugin specifically designed for Bootstrap 5. It leverages Bootstrap's Modal and Carousel components, ensuring a consistent look and feel with your existing Bootstrap 5 project. Listed in Bootstrap 5 Design Resources (see below).
• Chocolat: A free, lightweight, and responsive lightbox plugin that offers flexibility in how images are displayed (fullscreen or within a contain

3190. Find Minimum Operations to Make All Elements Divisible by Three

You are given an integer array nums. In one operation, you can add or subtract 1 from any element of nums. Return the minimum number of operations to make all elements of nums divisible by 3.
/**
 * @param {number[]} nums
 * @return {number}
 */
var minimumOperations = function(nums) {
    // Initialize a counter to keep track of total operations
    let operations = 0;

    // Loop through each number in the array
    for (let num of nums) {
        // Find the remainder when divided by 3
        let remainder = num % 3;

        // If remainder is 1, subtract 1 -> costs 1 operation
        // If remainder is 2, add 1 -> costs 1 operation
        // If remainder is 0, no operation n

SCTM-SSAS: Syntactic–Contextual Translation Framework

# SCTM-SSAS: Syntactic–Contextual Translation Framework This repository provides a research-oriented implementation of the two core components proposed in **“English translation semantic alignment mechanism combining syntactic mapping and context awareness for translation optimization”** by **Huiying Ye** and **Yanjie Ye**. :contentReference[oaicite:2]{index=2} The system integrates **syntactic mapping** and **contextual awareness** to build a translation process that is both grammatically coherent and semantically aligned. It consists of two main modules: - **SCTM — Syntactic-Contextual Translation Model** - **SSAS — Semantic-Syntactic Alignment Strategy** The goal is to bridge the gap between structural linguistic precision and dynamic contextual interpretation, enabling more fluent and semantically accurate translations. --- ## 1. Background Machine translation has long struggled with mismatches between: - syntactic structure - contextual nuances - semantic intentions Traditional rule-based systems preserved grammar but lacked adaptability, while statistical and deep learning models improved fluency at the cost of losing fine-grained structural control. This work proposes a unified mechanism that merges both syntactic dependency modeling and contextual embedding to enhance translation quality across diverse linguistic environments. --- ## 2. Model Overview ### **2.1 Syntactic Mapping Layer (from SCTM)** Based on the formulation in Section 3.3 (page 5–6) :contentReference[oaicite:3]{index=3}: - Dependency parsing constructs a syntactic graph - A syntactic relation matrix **S** encodes connection strengths - Structural similarity between words is computed using syntactic adjacency - Each word obtains a syntactic embedding aggregated from its neighbors This preserves grammatical relations and strengthens structural fidelity during translation. --- ### **2.2 Contextual Awareness Layer (SCTM)** As described in Section 3.3 (page 6–7) :contentReference[oaicite:4]{index=4}: - A bidirectional LSTM processes the full sentence - Global context vector **C** is computed - Hidden states are combined to form contextual embeddings - Word-level contextual similarity is calculated - Final contextual representation merges local and global signals This captures long-range dependencies and semantic nuances. --- ### **2.3 Attention Integration (SCTM)** Using Equation (15): - Syntactic embedding - Contextual embedding - Attention alignment are fused to generate target-side translation embeddings. --- ## 3. Semantic-Syntactic Alignment Strategy (SSAS) Section 3.4 (page 7–9) :contentReference[oaicite:5]{index=5} introduces SSAS as an optimization layer applied after SCTM output. ### SSAS consists of: 1. **Dynamic Syntactic Mapping** - Re-maps syntactic units between source and target - Computes syntactic distance & similarity - Improves structural alignment quality 2. **Contextual Adaptation** - BiLSTM-derived global context - Contextual similarity - Adjusted contextual embedding 3. **Adaptive Feedback Mechanism** - Alignment loss - Gradient-based updates - Feedback-corrected target embedding This iterative loop stabilizes translation outputs and increases consistency. --- ## 4. Key Features - Rich syntactic dependency modeling - Global-local contextual embedding fusion - Attention-based alignment for translation - Feedback-driven refinement with syntactic & semantic loss - Modular design suitable for multilingual or low-resource settings --- ## 5. Potential Applications - Machine translation systems - Syntactic parsing-based NLP pipelines - Context-aware language understanding - Cross-lingual semantic alignment research --- ## 6. Citation If you use this work, please cite: > Ye, H., & Ye, Y. *English translation semantic alignment mechanism combining syntactic mapping and context awareness for translation optimization.* :contentReference[oaicite:6]{index=6} --- ## 7. License You may choose any license suitable for academic or commercial use (MIT recommended).
import torch
import torch.nn as nn
import torch.nn.functional as F


# --------------------------------------------------------------------
# 1. Syntactic Mapping Layer
# --------------------------------------------------------------------

class SyntacticMapping(nn.Module):
    """
    Implements:
    - syntactic relation matrix S (eq.4)
    - adjacency g(i,j) (eq.5)
    - syntactic similarity (eq.6)
    - word-level syntactic embedding (eq.7)
    """

    def __init__(self, e

Diffusion-Physics-FX: Dynamic Film Scene Generation with Physical-Guided Diffusion

# Diffusion-Physics-FX: Dynamic Film Scene Generation with Physical-Guided Diffusion Diffusion-Physics-FX is an open-source implementation inspired by the paper *“A Film and Television Dynamic Scene Generation and Special Effects Synthesis System Integrating Diffusion Model and Physical Guidance Mechanism”* by Wenxiao Du and Xupeng Yao. This repository provides a research-oriented framework that blends diffusion-based generative modeling with physically guided constraints to produce dynamic, realistic, and coherent film scenes and special effects. The system introduces two main components: 1. **DDSSM — Diffusion-Driven Scene Synthesis Model** A multimodal diffusion architecture that iteratively refines latent representations of visual scenes using guidance from spatial–temporal features and transformer-enhanced multimodal encoders. 2. **DSSS — Dynamic Scene Synthesis Strategy** A physically grounded generation interface that enforces rules of gravity, momentum, collision, and structural constraints to ensure that the generated scenes are not just visually appealing but physically plausible. --- ## 1. Background Film and television productions increasingly require dynamic scenes that are: - High in visual fidelity - Spatially and temporally coherent - Physically realistic - Efficient to produce at scale Traditional systems rely on rule-based effects, handcrafted simulations, or pure generative models lacking physical consistency. Diffusion-Physics-FX addresses these gaps by integrating: - **Diffusion models** for high-quality iterative generation - **Graph-based physical constraints** rooted in real-world physics - **Multimodal encoders** capable of processing video, images, audio, text, and metadata - **Feedback refinement loops** that correct temporal drift, enforce scene continuity, and maintain narrative coherence --- ## 2. System Architecture Overview ### 2.1 Multimodal Encoder The multimodal encoder integrates signals from: - Visual frames - Audio cues - Textual scene descriptions - Motion or physical metadata As illustrated on page 5–6 of the paper :contentReference[oaicite:1]{index=1}, its transformer-based structure includes: - Cross-modal attention - Feature alignment modules - Joint latent representation - Policy & assessment submodules for guiding downstream diffusion This module transforms diverse signals into a unified latent space that conditions the diffusion generator. --- ## 3. Diffusion-Driven Scene Synthesis Model (DDSSM) DDSSM operates in the latent domain using a forward and reverse diffusion process: - **Forward process:** gradually injects Gaussian noise - **Reverse process:** denoises while injecting structural and physical constraints - **Graphical propagation layer:** enforces physical plausibility (gravity, collision, energy conservation) - **Contrastive refinement:** improves temporal alignment The architecture resembles Figure 1 in the paper (page 5) :contentReference[oaicite:2]{index=2}. The reverse denoising step incorporates physical guidance: - Corrects object positions - Ensures movements follow real-world laws - Stabilizes dynamic sequence transitions --- ## 4. Dynamic Scene Synthesis Strategy (DSSS) DSSS adds dynamic realism by embedding physics directly in the generation process. Its key components: - **Physics-guided constraints:** gravity, momentum, collision, rigid-body dynamics - **Feedback loop:** evaluates physical accuracy + visual coherence - **Iterative refinement:** corrects deviations frame-by-frame - **Scene-level optimization:** improves continuity between shots The feedback rule follows: Where C is coherence and P is physical accuracy. --- ## 5. Features - Multimodal transformer encoder - Diffusion-based temporal generation - Graphical propagation for physics constraints - Physically grounded motion and interaction - Feedback correction for coherence - Suitable for VFX, pre-visualization, animation, and creative pipelines --- ## 6. Applications - Film & TV visual effects - AI-assisted previsualization - Dynamic scene generation - Physics-aware animation - Special effects prototyping - Research in physics-guided generative modeling --- ## 7. Citation If you use this repository, cite the original paper: > Du, W., & Yao, X. *A film and television dynamic scene generation and special effects synthesis system integrating diffusion model and physical guidance mechanism.* --- ## 8. License You may apply MIT, Apache-2.0, or any license suited for your project’s intended use.
import torch
import torch.nn as nn
import torch.nn.functional as F


# ---------------------------------------------------------
# Basic Modules: MLP, Attention, Transformer blocks
# ---------------------------------------------------------

class MLP(nn.Module):
    def __init__(self, dim, hidden):
        super().__init__()
        self.fc1 = nn.Linear(dim, hidden)
        self.fc2 = nn.Linear(hidden, dim)
        self.act = nn.GELU()

    def forward(self, x):
        return 

curlコマンド一例

# curl コマンド一覧

## curlとは

curlは、コマンドラインからHTTPリクエストを送信するツール。Webブラウザが行うHTTPリクエストを、ターミナル上で実行できる。

### 基本動作

- HTTPプロトコルでサーバーにリクエストを送信
- サーバーからのレスポンスを標準出力に表示
- GET、POST、PUT、DELETE等のHTTPメソッドに対応
- JSON、XML、HTML等の任意のデータ形式を送受信可能

### 用途

- API動作確認
- Webサーバーの状態チェック
- ファイルダウンロード
- 自動化スクリプトでのHTTP通信
- パフォーマンス測定

### インストール

macOS: 標準でインストール済み
Windows 10/11: 標準でインストール済み
Linux: `apt install curl` 等でインストール

### 基本構文

```bash
curl [オプション] URL
```

### 最も基本的な使用例

```bash
# GETリクエスト(最もシンプル)
curl https://jsonplace

AgriControlNet: Image Recognition-Driven Control Strategy for Agricultural Machinery

# AgriControlNet: Image Recognition-Driven Control Strategy for Agricultural Machinery AgriControlNet is a unified framework integrating advanced image recognition with adaptive control strategy optimization for agricultural machinery. It is derived from the paper *"AgriControlNet: Image Recognition-Driven Control Strategy Analysis for Agricultural Machinery"* by Runkun Guo and Liang Shang. The project provides a reference PyTorch implementation for the key components introduced in the paper, including its multimodal encoder, graphical propagation layer, adaptive region pooling module, and the Adaptive Control Strategy for Agricultural Machinery (ACSAM). --- ## 1. Overview Modern agriculture requires intelligent systems capable of adjusting to dynamic, uncertain, and heterogeneous farming environments. AgriControlNet addresses this need by combining a powerful visual recognition architecture with a domain-aware adaptive control strategy. Its goals include: - Robust feature extraction under challenging agricultural conditions - Real-time control signal generation from visual inputs - Adaptation to uncertainties such as weather, crop density, and terrain variability - Multi-objective optimization for sustainable farming operations The framework is built around three key modules: ### **1. AgriControl Recognition Network (ACRN)** A visual encoder combining: - Hierarchical Mixed Mamba blocks - Patch ghosting for multi-scale features - Spatial-temporal modeling - Graphical propagation for structured dependency learning - Adaptive Region Pooling for efficient feature aggregation The architecture is designed to handle agricultural image challenges such as: - Lighting variability - Dust and occlusion - Crop diversity - Machine motion noise ### **2. Adaptive Control Strategy for Agricultural Machinery (ACSAM)** ACSAM maps extracted visual features to actionable control signals. It includes: - Multimodal decision integration - Predictive modeling to anticipate future states - Real-time feedback-driven adaptation - Multi-objective optimization for efficiency and sustainability Control variables supported include: - Steering and direction - Machinery speed - Tool engagement and switching - Machine–crop interaction constraints --- ## 2. Architecture Summary ### **2.1 Multimodal Encoder (ACRN)** The encoder integrates: - Residual multi-scale CNN layers - Attention-based adjacency matrices - Graphical propagation (message passing across spatial regions) - Adaptive pooling based on semantic relevance It transforms raw images into a compact, robust feature representation suitable for control decision-making. ### **2.2 Graphical Propagation Layer** This layer models spatial dependencies using: - Learned adjacency matrices - Degree normalization - Context-aware feature propagation This is essential for recognizing machinery position, crop row alignment, obstacles, and field structure. ### **2.3 Adaptive Region Pooling (ARP)** ARP dynamically allocates pooling regions based on feature distributions. Unlike fixed pooling, ARP: - Preserves semantically relevant regions - Reduces computation - Increases robustness across environmental conditions ### **2.4 ACSAM Decision Module** ACSAM integrates: - Visual features - Operational metrics (soil resistance, crop density, weather data) - Predictive state modeling - Feedback loops for online improvement ACSAM can enforce domain constraints such as: - Maximum soil compaction - Minimum crop damage - Safety and equipment protection thresholds --- ## 3. Key Features - **High accuracy** in agricultural machinery recognition - **Robustness** to noise, occlusion, and environmental change - **Real-time capability** with lightweight architectural elements - **Multimodal integration** supporting visual and sensor fusion - **Adaptive optimization** aligning performance and sustainability - **Scalable and modular design** suitable for various agricultural tasks --- ## 4. Experimental Summary As reported in the paper, AgriControlNet outperforms prior baselines such as ResNet, ViT, I3D, DenseNet, MobileNet, and BLIP across multiple datasets: - Agricultural Machinery Image Dataset - Crop Field Machinery Control Dataset - Precision Farming Vision Dataset - Smart Agriculture Equipment Dataset Improvements include: - +3–4% accuracy - Higher robustness under noise and occlusion - Lower computational load compared to heavy backbones - Strong cross-dataset generalization --- --- ## 5. Usage ### **Training** Prepare datasets containing: - Field images - Machinery annotations - Control signals or labels - Environmental context metadata Define hyperparameters in the config file, then run the training script. ### **Inference** Call the model with: - ACRNEncoder(image) - ACSAM(decision_inputs) The output includes predicted control actions such as direction, velocity, tool adjustment, or operational state. --- ## 6. Citation If you use this repository, please cite the original paper: > Guo, R., & Shang, L. *AgriControlNet: Image Recognition-Driven Control Strategy Analysis for Agricultural Machinery.* --- ## 7. License You may assign any appropriate open-source license (MIT recommended). --- ## 8. Acknowledgment This implementation is inspired by the AgriControlNet framework introduced by **Runkun Guo** and **Liang Shang**.
import torch
import torch.nn as nn
import torch.nn.functional as F


# ==========================================================
# Basic building blocks
# ==========================================================

class ConvBNReLU(nn.Module):
    """Basic conv → BN → ReLU"""
    def __init__(self, in_ch, out_ch, k=3, s=1, p=1):
        super().__init__()
        self.conv = nn.Conv2d(in_ch, out_ch, k, s, p, bias=False)
        self.bn = nn.BatchNorm2d(out_ch)
        self.act = 

DissemiGraph-SEM-GUIDE: Semantic-Aware Content Dissemination in the Fourth Classroom

# DissemiGraph-SEM-GUIDE: Semantic-Aware Content Dissemination in the Fourth Classroom This repository provides a reference implementation of **DissemiGraph** and **SEM-GUIDE**, a dual-module framework for modeling and optimizing content dissemination in *Fourth Classroom* environments. The approach is based on the paper: > "Recognition and Optimization of Fourth Classroom Content Dissemination Patterns Using Deep Learning Techniques" > by Gang Deng, Siyi Chen, and Yujie Huang. The goal of this project is to translate the core ideas of the paper into a practical, extensible codebase that can be used for research, prototyping, and educational experiments. --- ## 1. Background The **Fourth Classroom** refers to informal, flexible, and often decentralized learning spaces that arise on digital platforms and social media. Unlike traditional classrooms, these environments: - Are **peer-driven** and **interest-driven**. - Have highly **dynamic content** and user interactions. - Exhibit **complex dissemination patterns** that are hard to model with simple heuristics. Conventional dissemination models usually assume: - Static network structures. - Homogeneous users. - Limited or no semantic awareness of the content being propagated. As a result, they struggle to capture: - Semantically nuanced patterns of content flow. - Temporal dynamics and attention shifts. - The alignment between user interests and content topics. DissemiGraph and SEM-GUIDE are designed to address these issues in an integrated way. --- ## 2. Model Overview ### 2.1 DissemiGraph **DissemiGraph** is a graph-based deep learning model for predicting and analyzing how educational content spreads in a user network. It focuses on three aspects: 1. **Content-Aware Initialization (CAI)** - Builds initial node representations by combining: - User profile features (e.g., prior knowledge, preferences). - Content semantic embedding (e.g., from text, images, interactions). - Initial engagement or relevance scores. - Applies a learnable projection and an optional time-gating mechanism to inject temporal readiness (user activity patterns). 2. **Semantic-Guided Propagation (SGP)** - Performs message passing on the user graph. - Uses semantic-aware attention to decide how strongly each neighbor influences a target node. - Weights messages by: - The similarity between user profiles and the content embedding. - A learnable semantic projection space that adapts to the task. 3. **Temporal Dissemination Prediction (TDP)** - Uses recurrent units to evolve node states over time. - Incorporates: - Temporal decay to down-weight outdated interactions. - Bilinear compatibility between sender and receiver states. - Semantic similarity between users and content. - Produces a dissemination likelihood for each edge and time step, optionally smoothed over a temporal window. ### 2.2 SEM-GUIDE **SEM-GUIDE** (Strategic Enhancement Mechanism for Guided Dissemination) sits on top of DissemiGraph and focuses on **optimization** rather than pure prediction: 1. **Strategic Node Selection** - Computes an intervention score for each user based on: - Semantic alignment with content. - Temporal engagement volatility. - Attention availability (cognitive budget). - Network connectivity (how influential the user is). - Selects high-impact users as targets for intervention (e.g., targeted recommendations, reminders). 2. **Guided Message Recalibration** - Adjusts propagation probabilities for selected users. - Emphasizes neighbors whose profiles are compatible with the content. - Incorporates a time-dependent factor so that interventions are aligned with user activity rhythms. 3. **Adaptive Feedback Mechanism** - Uses a feedback loop (e.g., engagement rewards) to compare predicted vs. actual outcomes. - Updates intervention scores over time. - Reduces cumulative error and improves strategy quality as more interaction data is observed. --- ## 3. Repository Structure A suggested structure for this project is: - `model.py` Core implementation of DissemiGraph and SEM-GUIDE (PyTorch). - `datasets/` Utilities and placeholders for dataset loaders compatible with the paper’s setting. - `configs/` Configuration files (hyperparameters, architecture settings). - `scripts/` Example training, evaluation, and experimentation scripts. - `examples/` Small-scale synthetic or toy examples illustrating usage. - `README.md` You are here. --- ## 4. Data Representation The models expect data in a form that is consistent with the paper’s formalization: - **Content set** - A collection of content units, each with: - A semantic embedding vector (e.g., from a text encoder or multimodal encoder). - Optional time-dependent semantic drift representation. - **User set** - A collection of users or participants, each with: - A dynamic profile vector that may evolve over time. - Engagement features or history with specific content. - **Interaction graph** - A time-dependent graph where: - Nodes represent users. - Edges represent interactions or influence (e.g., shares, replies, mentions). - Edge weights store influence strengths, timestamps, or other interaction metadata. - **Dissemination tensor** - A tensor recording which content has reached which user at which time step, possibly with graded strengths. The provided `model.py` focuses on the modeling components; dataset handling and preprocessing can be customized to your concrete application. --- ## 5. Installation You can set up a Python environment along the following lines: 1. Create and activate a virtual environment. 2. Install dependencies (for example, a deep learning framework and common utilities). Typical dependencies include: - A deep learning library (such as PyTorch). - NumPy and SciPy. - Tools for handling graphs and mini-batch processing. - Logging and experiment tracking utilities. You can maintain a `requirements.txt` file in the repository and install everything with a single command. --- ## 6. Usage A typical workflow might look like this: 1. **Prepare data** - Build or load the interaction graph for your platform. - Compute or load semantic embeddings for content. - Extract user features and engagement histories. - Convert everything to tensors and adjacency structures. 2. **Configure the model** - Define: - Embedding dimensions. - Number of graph propagation layers. - Hidden dimensions for recurrent units. - Choice of activation functions, dropout, and other regularization. 3. **Train** - Instantiate `DissemiGraph` (and optionally `SEMGuide`). - Define a loss function based on: - Prediction tasks (e.g., next dissemination step, link prediction). - Optimization targets (e.g., gain, engagement metrics). - Iterate over time windows and mini-batches of user-content pairs. - Optionally log metrics like F1, AUC, and dissemination gain. 4. **Evaluate** - Measure: - Semantic coherence of predicted dissemination paths. - Efficiency (how quickly content reaches relevant users). - Controllability (how strongly interventions change the dissemination pattern). 5. **Deploy / Simulate** - Use the trained model to: - Predict how new content will spread. - Identify strategic users for content seeding. - Run simulations under different intervention policies. --- ## 7. Extensibility This repository is intended as a **research-friendly starting point**. You can extend it in multiple directions: - Plug in different text or multimodal encoders to generate content embeddings. - Swap GRU with other sequence models (e.g., LSTM or Transformer encoders). - Experiment with different attention mechanisms for message passing. - Integrate reinforcement learning agents to drive SEM-GUIDE’s intervention policy. - Add explanation modules or visualization tools for dissemination graphs. --- ## 8. Citation If you use this implementation or ideas derived from it in your research, please cite the original paper by Gang Deng, Siyi Chen, and Yujie Huang. --- ## 9. License You may choose an open-source license that fits your project goals (for example, MIT, Apache-2.0, or GPL). Add the corresponding `LICENSE` file at the root of the repository. --- ## 10. Acknowledgements This implementation is inspired by the formal framework, DissemiGraph model, and SEM-GUIDE optimization strategy described in the original paper on Fourth Classroom content dissemination. All credit for the conceptual design of the method goes to the authors.
from __future__ import annotations

from dataclasses import dataclass
from typing import Optional, Dict, Any, Tuple

import torch
from torch import nn
from torch.nn import functional as F


# ---------------------------------------------------------------------------
# Utility modules
# ---------------------------------------------------------------------------


class MLP(nn.Module):
    """Simple multi-layer perceptron with optional dropout and activation."""

    def __init_

BACE-CICI: Multimodal Learning Behavior Analysis and Competence-Aware Curriculum Modeling

# BACE-CICI: Multimodal Learning Behavior Analysis and Competence-Aware Curriculum Modeling This repository provides a research-oriented implementation inspired by the paper *“Multimodal Fusion for Analyzing English Learning Behaviors and Competence Assessment”* by **Long Shi**. :contentReference[oaicite:2]{index=2} It contains two core components: - **BACE — Behaviorally Augmented Competence Embedding** - **CICI — Competence-Informed Curriculum Inference** The project aims to support computational modeling of English learning behaviors using multimodal signals such as linguistic content, behavioral logs, temporal indicators, and task complexity descriptors. --- ## 1. Background Modern digital learning environments generate abundant multimodal interaction data, including: - correctness logs - response times - revision behaviors - eye-gaze, speech, gesture, or platform interactions - task difficulty descriptors Traditional learning analytics approaches rely on static test scores or manually curated features, which overlook rich behavioral dynamics and temporal competence evolution. As discussed in Section 1 of the paper, these limitations hinder personalized feedback, adaptive sequencing, and cognitive-aware modeling. :contentReference[oaicite:3]{index=3} The BACE–CICI framework integrates deep multimodal representation learning with curriculum optimization to address these gaps. --- ## 2. Model Overview ### 2.1 Multimodal Encoder Architecture (BACE) Figure 1 and Figure 2 in the paper describe an encoder architecture combining: - pretrained text encoder for linguistic complexity - nonlinear behavior encoder for correctness, latency, and behavioral vectors - task complexity embedding - wavelet-enhanced blocks, SEB blocks, and channel-attention mechanisms - graphical propagation to refine fused representations - gated residual fusion combining behavioral and linguistic inputs Together these produce unified representations of learner–task interactions. :contentReference[oaicite:4]{index=4} --- ### 2.2 Behaviorally Augmented Competence Embedding (BACE) BACE unifies three multimodal streams: - **lt:** textual embedding of task-level linguistic input (Eq. 10) - **bu,t:** behavioral embedding (Eq. 11) - **ct:** task difficulty & structural features (Eq. 12) The three components are joined with a learned gated residual mechanism (Eq. 13–15), forming: A self-attention pooling layer aggregates learner histories into a competence embedding hu (Eq. 16), which then passes through a projection network to produce the final competence estimate cu (Eq. 17). Task-level correctness prediction is performed via Eq. (18). Competence smoothness regularization (Eq. 19) stabilizes trajectories across sessions. :contentReference[oaicite:5]{index=5} --- ## 3. Competence-Informed Curriculum Inference (CICI) CICI formulates curriculum sequencing as a constrained optimization problem over competence trajectories. ### 3.1 Competence Gap Projection & Feasibility Masking For each candidate task tj: - compute competence gap Δ (Eq. 21) - filter tasks exceeding cognitive stretch δmax (Eq. 22) Figure 4 illustrates how diverse task representations are processed via dilated depthwise convolutions and feasibility constraints. :contentReference[oaicite:6]{index=6} --- ### 3.2 Learning Gain Estimation Expected learning gain from a task is modeled by: (Equation 23). A curriculum smoothness constraint ensures topical continuity using cosine similarity (Eq. 24). --- ### 3.3 Curriculum Optimization & Diversity Regularization Candidate tasks are sampled via a softmax strategy (Eq. 25) with exploration controlled by τ. Competence evolves through expected increments (Eq. 26). Curriculum utility includes penalties for incoherent topic transitions (Eq. 27) and diversity regularization across selected tasks (Eq. 29). The optimal curriculum segment S* maximizes expected reward (Eq. 28). :contentReference[oaicite:7]{index=7} --- ## 4. Features - Multimodal linguistic + behavioral fusion - Wavelet / SEB / CA-based feature hierarchy - Graphical propagation for temporal and semantic task structure - Competence trajectory modeling with smoothness regularization - CICI curriculum inference integrating feasibility, gain, and diversity - Personalized task sequencing for real-time adaptation --- ## 5. Potential Applications - English learning analytics - Personalized task recommendation - Learner modeling and competence prediction - Adaptive curriculum design - Educational data mining - Multimodal behavior analysis --- ## 6. Citation If you use this repository: > Shi, L. *Multimodal Fusion for Analyzing English Learning Behaviors and Competence Assessment.* :contentReference[oaicite:8]{index=8} --- ## 7. License You may release the project under MIT, Apache-2.0, or another open-source license depending on your intended distribution model.
import torch
import torch.nn as nn
import torch.nn.functional as F


# =====================================================
# Utility Layers
# =====================================================

class FeedForward(nn.Module):
    def __init__(self, dim, hidden=256):
        super().__init__()
        self.fc1 = nn.Linear(dim, hidden)
        self.fc2 = nn.Linear(hidden, dim)
        self.act = nn.GELU()

    def forward(self, x):
        return self.fc2(self.act(self.fc1(x)))

LSAN-CGAT: Deep Learning–Based Adaptive Tutoring for English Language Acquisition

# LSAN-CGAT: Deep Learning–Based Adaptive Tutoring for English Language Acquisition **LSAN-CGAT** is a research-oriented implementation of a **deep learning–based adaptive tutoring framework** for English language acquisition. It is inspired by the paper: *“Enhancing English Language Acquisition through Deep Learning-Based Adaptive Tutoring Systems”* by Xi Yang and Ling Li. The framework integrates: - **Lexical-Semantic Alignment Network (LSAN)** for multimodal learner modeling - **Curriculum-Guided Adaptive Transfer (CGAT)** for adaptive training and deployment to provide **personalized, multimodal, and curriculum-aware English tutoring**. --- ## 1. Motivation Traditional digital language learning systems suffer from: - static content and fixed exercise sequences - limited personalization beyond basic difficulty levels - rule-based feedback that fails to capture rich learner errors - weak integration of speech, text, and semantic information These issues reduce engagement and limit support for diverse learners. Recent progress in deep learning and large-scale language models enables: - joint lexical, semantic, and phonological learner modeling - modeling of complex interaction histories - dynamic content and difficulty adaptation based on real-time performance - curriculum design aligned with cognitive principles of second language acquisition **LSAN-CGAT provides a computational framework that incorporates these capabilities.** --- ## 2. System Overview LSAN-CGAT consists of two tightly coupled modules: ### **1. Lexical-Semantic Alignment Network (LSAN)** A multimodal language model that jointly learns lexical, semantic, and phonological representations. ### **2. Curriculum-Guided Adaptive Transfer (CGAT)** A curriculum-aware training and scheduling strategy that adapts to learner profiles and supports cross-task transfer. Together, they enable: - fine-grained learner modeling - task-specific supervision - curriculum-aware learning trajectories - cross-domain robustness for different learning settings --- ## 3. Lexical-Semantic Alignment Network (LSAN) LSAN is a multimodal language model tailored for English education tasks. ### 3.1 Multimodal Lexical Representation For each token, LSAN builds **three parallel embeddings**: - **Lexical embedding** (subword + token identity) - **Semantic embedding** (context windows + gloss meanings) - **Phonological embedding** (IPA / phoneme sequences) These are concatenated into a **multimodal lexical vector**, representing: - orthographic form - contextual semantics - pronunciation features Figure 1 (page 9) illustrates the patch-like embeddings and multimodal pathway. --- ### 3.2 Dual-Path Encoder LSAN uses two complementary encoding paths: 1. **Structural transformer** — models syntax and sequence patterns 2. **Semantic graph encoder** — operates on dependency and sense graphs A fusion module aligns outputs from both paths, producing rich token-level representations that encode: - grammatical relations (e.g., tense, agreement) - semantic disambiguation - graph-based syntactic and semantic propagation --- ### 3.3 Educational Objectives and Losses LSAN is trained using multiple pedagogically motivated objectives: - **Form-oriented loss** (grammar correctness, POS, error type prediction) - **Semantic alignment loss** (embedding ↔ gloss consistency) - **Phonological contrastive loss** (distinguish sound-alike words) - **Task-specific loss** (classification, tagging, generation) Additional self-supervised objectives include: - masked token modeling - multimodal embedding reconstruction These correspond to Section 3.3 and Figures on pages 9–10 of the paper. --- ## 4. Curriculum-Guided Adaptive Transfer (CGAT) CGAT governs training, task ordering, adaptation, and deployment. ### 4.1 Curriculum Scheduling CGAT organizes tasks such as: - grammar recognition - vocabulary expansion - sentence ordering - reading comprehension - listening discrimination Each task has: - difficulty level - performance score - curriculum phase role A **soft curriculum scheduler** balances: - intrinsic difficulty - performance deficits This enables: - prioritizing tasks where the learner struggles - maintaining exposure to mastered skills - smooth progression from simple → complex abilities --- ### 4.2 Transfer-Aware Training CGAT maintains a **task transfer matrix** that models: - positive transfer - interference - cross-task relationships Gradients are reweighted during optimization to: - enhance beneficial transfer - suppress harmful interference Especially helpful when dealing with: - shared linguistic structures - domain differences - mixed educational corpora --- ### 4.3 Learner-Specific Adaptation Each learner is represented by a **latent learner vector** encoding: - proficiency level - native language influence - cognitive style - interaction history This vector modulates: - task sampling probabilities - curriculum progression - per-sample loss weighting A **feedback gating mechanism** uses correctness and confidence to adjust learning contribution—enabling fine-grained personalization. --- ### 4.4 Domain Robustness CGAT uses **domain-adversarial training** to build domain-invariant representations while preserving useful domain distinctions. Figure 3 shows the architecture: LSAN + scheduler + transfer module + learner adaptation. --- ## 5. Datasets and Evaluation The LSAN-CGAT framework is evaluated on multiple English language learning datasets: - **Cambridge English Profile (CEP)** - **EFCAMDAT** - **Duolingo SLAM** - **CALLHOME / CALLFRIEND English** **Experimental setup:** - Transformer-based backbone - Adam optimizer + mixed precision - Cross-entropy / MSE losses - Metrics: accuracy, F1, precision, recall, AUC, error-based metrics **LSAN-CGAT consistently outperforms** strong baselines (3D CNNs, transformer trackers, multimodal models), showing robust and adaptive learning behavior. --- ## 6. Integration in an Adaptive Tutoring System A practical LSAN-CGAT pipeline includes: ### **1. Interaction Collection** - Collect learner responses - Log timings, errors, metadata ### **2. LSAN-Based Analysis** - Convert input into multimodal embeddings - Use dual-path encoders - Predict grammatical labels, semantic matches, or rewritten text ### **3. Feedback & Recommendation** - Provide natural-language feedback - Highlight semantic issues & grammar errors - Tailor suggestions to learner level ### **4. CGAT Curriculum Adaptation** - Update difficulty & performance estimates - Schedule next tasks - Update learner profile vectors ### **5. Continuous Improvement** - Ongoing model updates - Support for new domains or corpora --- ## 7. Extensibility The LSAN-CGAT framework is modular and can be extended by: - incorporating pretrained LMs or speech encoders - adding image/text multimodal components (as hinted in Figure 2) - integrating explainable AI for instructor dashboards - linking with institutional learning analytics - combining with conversational agents for dialogue practice --- ## 8. Citation If you use or adapt this project, please cite: > Yang, X., & Li, L. > *Enhancing English Language Acquisition through Deep Learning-Based Adaptive Tutoring Systems.* --- ## 9. Disclaimer This repository is a **research prototype**, not a production-ready tutoring platform. Any real-world deployment must ensure: - robust privacy and data protection - fairness and bias mitigation - accessibility and inclusivity - evaluation with target populations Use the framework responsibly within legal and institutional constraints.
from __future__ import annotations

from dataclasses import dataclass
from typing import Dict, List, Optional, Tuple

import math
import torch
import torch.nn as nn
import torch.nn.functional as F


# ---------------------------------------------------------------------------
# Helper: simple multi-layer perceptron
# ---------------------------------------------------------------------------


class MLP(nn.Module):
    """Simple MLP with configurable depth and dropout."""

   

CreditGraphFormer: Privacy-Aware Federated Enterprise Credit Rating

# CreditGraphFormer: Privacy-Aware Federated Enterprise Credit Rating **CreditGraphFormer** is a research-oriented implementation of a **privacy-aware, federated learning framework** for enterprise credit rating with fiscal big data. It is inspired by the paper: *“Privacy-Aware Federated Learning for Enterprise Credit Rating with Fiscal Big Data”* by Xuan Huang. The framework integrates: - **CreditGraphFormer** — a graph-based transformer encoder, - **RegulaLogic** — a compliance-driven reasoning layer, - **A privacy-aware federated training pipeline**, to support trustworthy enterprise credit assessment under regulatory and data-protection constraints. --- ## 1. Background and Motivation Enterprise credit rating is essential for: - financial risk management, - lending and loan approval, - regulatory supervision. ### Modern fiscal environments feature: - Massive heterogeneous data: tax records, invoices, regulatory filings, transaction logs. - Distributed data silos across tax bureaus, banks, payment platforms, regulators. - Data protection laws (e.g., GDPR and local regulations) that restrict centralized data pooling. ### Challenges in traditional methods: - Dependence on static statements and handcrafted indicators. - Insufficient capacity for large-scale fiscal big data. - Centralized training pipelines that raise privacy and compliance risks. - Lack of alignment with regulatory logic and audit semantics. Federated learning provides a collaborative training structure without data sharing—but requires: - fiscal-domain architectures, - robust privacy mechanisms, - regulatory-aware reasoning. **CreditGraphFormer** addresses these needs. --- ## 2. Problem Setting Enterprise credit rating is formulated as **representation learning on a fiscal knowledge graph**. ### Graph structure: - **Nodes**: enterprises with high-dimensional fiscal attributes. - **Edges**: invoice flows, supply-chain links, equity holdings, legal ties. - **Temporal attributes**: tax indicators, revenue sequences, audits over time. ### Formalization: - Enterprises form the set of rating targets. - Ratings use **ordinal labels** (e.g., AAA → C). - A **fiscal knowledge graph** contains: - nodes for enterprises and regulators, - heterogeneous relations, - time-varying enterprise feature vectors. ### Goals: - Predict enterprise ratings, - Integrate regulatory compliance, - Maintain cross-institution privacy, - Achieve robustness under distribution shifts. --- ## 3. Framework Overview The framework consists of three coordinated components: ### **1. CreditGraphFormer** A transformer-based graph encoder for fiscal networks that are: - **asymmetric**, - **sparse**, - **temporal**. It integrates: - multimodal feature projection, - relation-specific message passing, - temporal stability embeddings, - a regulatory-aware transformer block. (Architecture shown on page 5 of the paper.) --- ### **2. RegulaLogic** A compliance-oriented reasoning layer incorporating: - compliance constraints, - audit overrides, - industry-specific rating floors, - temporal smoothing, - policy-rule penalties, - confidence calibration. (Shown in diagrams on pages 8 and 14.) --- ### **3. Privacy-Aware Federated Pipeline** A federated setup where: - Clients keep data locally, - Knowledge is shared via secure aggregation and differential privacy, - Heterogeneous data distributions are handled via domain-specific modeling and local personalization. --- ## 4. CreditGraphFormer: Graph-Based Transformer for Fiscal Big Data ### 4.1 Multimodal Feature Projection Attributes are projected into multiple **fiscal views**, such as: - tax declarations & VAT indicators, - balance-sheet metrics, - audit statistics, - invoice and transaction patterns. Each view uses its own projection matrix, producing a multimodal embedding. (Shown on page 6 of the paper.) --- ### 4.2 Heterogeneous Relational Attention For each relation type, the model applies: - relation-specific transformations, - neighbor attention mechanisms, - bilinear compatibility scoring. This supports: - risk propagation across invoice networks, - supply-chain dependency modeling, - reputation propagation through ownership/legal links. --- ### 4.3 Regulatory-Aware Transformer Encoder A regulatory mask influences transformer attention: - Audited/flagged nodes can be masked or down-weighted. - Attention computations incorporate compliance constraints. - Residual and feed-forward blocks follow transformer standards. This ensures regulatory knowledge is encoded structurally. --- ### 4.4 Temporal Stability Embedding Temporal differences between consecutive periods produce a **stability descriptor**: - Small changes → stable enterprises, - Large changes → high volatility. Combined with graph embeddings, this forms the final enterprise representation. --- ## 5. RegulaLogic: Compliance-Driven Reasoning Layer RegulaLogic ensures predictions are **policy-consistent and interpretable**. ### Mechanisms include: - **Compliance masks** (filing timeliness, penalties, transparency). - **Rule-based penalties** for: - high audit risk, - recurring compliance violations, - tax anomalies or invoice irregularities. - **Sector-based rating floors** ensuring industry-specific minimum caps. - **Temporal smoothing** to avoid unstable predictions. - **Confidence calibration**: - High uncertainty → fallback to sector median. RegulaLogic bridges machine learning and regulatory logic. --- ## 6. Privacy-Aware Federated Learning Designed for multi-institution collaboration: - Local data never leaves the client. - Secure aggregation protects model updates. - Differential privacy controls information leakage. ### Typical FL parameters: - Local epochs per communication round, - Global aggregation rounds, - Client sampling strategies, - DP noise multipliers and clipping norms. Experiments in the paper show improvements in: - accuracy and F1, - robustness under label noise and distribution shifts, - regulatory adherence versus baselines (GraphSAGE, CNN-LSTM, Transformers, TabNet). --- ## 7. Potential Usage Scenarios CreditGraphFormer + RegulaLogic can support: - enterprise credit rating and risk tiering, - regulatory early-warning systems, - bank loan approval and credit limit setting, - supply-chain risk propagation, - scenario simulations under regulatory policy changes. The architecture can generalize to other privacy-sensitive financial graph tasks. --- ## 8. Extensibility Possible extensions include: - Integrating legal documents or scanned contracts, - Exploring personalized FL or advanced federated optimizers, - Adding adversarial defenses for malicious clients, - Hybridizing RegulaLogic with neural-symbolic rule learning, - Using advanced temporal models or change-point detection. --- ## 9. Citation If using this framework, please cite: > Huang, X. > *Privacy-Aware Federated Learning for Enterprise Credit Rating with Fiscal Big Data.* --- ## 10. Disclaimer This repository provides a **conceptual, research-style implementation**. Not suitable for production deployment without: - rigorous testing, - domain expert evaluation, - legal and compliance review, - strict adherence to relevant data protection laws. Use responsibly and within applicable regulatory frameworks.
from __future__ import annotations

from dataclasses import dataclass
from typing import Dict, List, Optional, Tuple

import math
import torch
import torch.nn as nn
import torch.nn.functional as F


# ---------------------------------------------------------------------------
# Utility: simple MLP
# ---------------------------------------------------------------------------


class MLP(nn.Module):
    """Simple multi-layer perceptron."""

    def __init__(
        self,
    

FairCoDNet for Tax Risk Identification

# FairCoDNet for Tax Risk Identification FairCoDNet for Tax Risk Identification is a research-oriented fairness-aware regression framework designed for enterprise tax risk identification based on multi-source fiscal and tax data. It is inspired by the paper *“Study on the enterprise tax risk identification model based on multi-source fiscal and tax data”* by Xuan Huang. The framework aims to build **predictive**, **interpretable**, and **fairness-controlled** models that can support tax risk scoring, fiscal supervision, and data-driven governance in modern tax administrations. --- ## 1. Background and Motivation Modern tax systems operate under conditions where: - Enterprises generate large volumes of heterogeneous financial data. - Tax authorities collect information from multiple digital systems. - Data sources include invoices, financial statements, transaction logs, regulatory filings, and public information. Traditional tax risk identification methods typically rely on: - Single-source financial statements, - Static rule-based systems, - Simple statistical or machine learning models with no fairness guarantees. These approaches suffer from: - Fragmented and heterogeneous data, - Limited interpretability, - Low adaptability to complex enterprise behaviors, - Lack of explicit fairness control regarding sensitive attributes. The referenced paper proposes a hybrid framework integrating multi-source tax data, knowledge engineering, and fairness-constrained regression to achieve both **high performance** and **accountability**. --- ## 2. Conceptual Overview This repository implements a conceptual version of the framework, centered on **FairCoDNet**. FairCoDNet is a regression model that: - Separates sensitive and non-sensitive features, - Controls the influence of sensitive attributes via a Coefficient of Determination (CoD)–based fairness constraint, - Is optimized using Constraint-Aware Optimization Dynamics (CAOD). Use cases include: - Enterprise tax risk scoring, - Fairness-aware financial risk prediction, - Auditing and supervision scenarios requiring transparency. The architecture diagram on page 6 of the paper illustrates the integration of convolutional encoders, tokenized adaptive modules, and fairness-aware components. --- ## 3. Multi-Source Fiscal and Tax Data The original work emphasizes multi-source data integration, including: ### **Structured Data** - Accounting records and ledgers, - Tax filings and declarations, - Invoice and transaction logs, - Financial ratios and indicators. ### **External and Semi-Structured Data** - Market indicators and macroeconomic variables, - Company disclosures and registry information, - Legal documents and case records, - News and regulatory bulletins. ### **Unstructured Data (optional)** - Textual descriptions in reports, - Scanned or image-based documents, - Enterprise social or relational networks. The model assumes the feature set can be decomposed into: - **Sensitive attributes**, - **Non-sensitive attributes** describing financial and operational behavior. A key preprocessing step is **orthogonalizing non-sensitive features** with respect to sensitive features to better disentangle their effects. --- ## 4. FairCoDNet: Fairness-Aware Regression ### 4.1 Problem Setting The main task is a regression problem: - **Target:** a real-valued tax risk score. - **Input:** a feature vector split into sensitive and non-sensitive components. FairCoDNet aims to: 1. Minimize prediction error, 2. Constrain the CoD attributable to sensitive features. ### 4.2 Coefficient Decoupling Strategy FairCoDNet introduces a strategy to decouple contributions from sensitive and non-sensitive features: - Each component is parameterized separately. - A **mixing coefficient** controls how much sensitive information influences the output. - The model can move smoothly along a **fairness–accuracy trade-off curve**. Advantages: - Highly interpretable influence of sensitive features, - Analytical control over fairness, - Adjustable fairness constraints without retraining. ### 4.3 CoD-Based Fairness Constraint FairCoDNet: - Computes the CoD of sensitive attributes as the fraction of output variance they explain, - Enforces a **budget** limiting this fraction, - Converts the fairness ratio into a **second-order cone constraint** for convex optimization. The constraint can be used either as: - A regularization term, or - A projection step during gradient updates. --- ## 5. Constraint-Aware Optimization Dynamics (CAOD) CAOD is the optimization mechanism designed for efficient and stable fairness-constrained training. ### **Key Components** #### **1. Conic Reformulation** - Transforms the fairness constraint into a second-order cone, - Ensures a convex feasible region. #### **2. Fairness-Guided Parameter Updates** - Tracks a fairness trajectory during training, - If the constraint is violated: - Rescales sensitive parameters, - Adjusts the mixing coefficient. This creates a dynamic feedback loop between fairness control and gradient descent. #### **3. Convex Relaxation Phase** - After convergence, a convex refinement step is applied, - The problem is relaxed within a convex hull of fairness–variance trade-offs, - A convex solver provides a globally optimal fair solution. Figures 3 and 4 in the paper illustrate these mechanisms. --- ## 6. Datasets and Evaluation (Conceptual) Although the paper focuses on tax risk, the experiments use financial datasets involving numbers, legal texts, and multimodal content: - **BR-TaxQA-R**: legal tax question answering, - **FinQA**: financial numeric reasoning, - **KPI-EDGAR**: mapping disclosures to KPIs, - **FinMME**: multimodal financial documents. In this repository, FairCoDNet is **dataset-agnostic**. To apply it: 1. Map your enterprise tax data into sensitive and non-sensitive feature sets, 2. Provide a target risk score, 3. Compute sample covariances, 4. Specify a fairness budget. ### **Evaluation metrics include:** - MSE, MAE (regression), - Classification metrics (if scores are thresholded), - Fairness metrics derived from CoD decomposition. --- ## 7. Usage Pattern (High-Level) ### **Data Preparation** - Integrate multi-source enterprise-level tax data, - Clean and normalize features, - Separate sensitive / non-sensitive attributes, - Optionally residualize non-sensitive features. ### **Model Initialization** - Set input dimensions, - Configure fairness budget, - Specify initial mixing coefficient. ### **Training** - Compute regression loss, - Apply fairness-aware CAOD updates, - Monitor fairness trajectory and convergence. ### **Evaluation & Interpretation** - Inspect CoD and sensitivity contributions, - Analyze sensitive attribute influence, - Use results to support tax audits or policy design. --- ## 8. Extensibility The framework is modular and extensible. ### **Feature Engineering** - Graph-based enterprise networks, - Legal text or unstructured feature integration, - Temporal or sequential features. ### **Fairness Modeling** - Alternative fairness definitions, - Post-hoc explanations and counterfactual analysis. ### **Optimization Strategies** - Replace or complement CAOD, - Multi-task learning (fairness + robustness). ### **Application Domains** - Credit scoring, - Loan underwriting, - Compliance modeling, - Adaptation to different regulatory systems. --- ## 9. Citation If you use this repository, please cite: > Huang, X. > *Study on the enterprise tax risk identification model based on multi-source fiscal and tax data.* --- ## 10. Disclaimer This implementation is conceptual and experimental. It is **not production-ready**. Real-world deployment requires: - Rigorous testing, - Legal and compliance review, - Privacy protection, - Alignment with regulatory standards.
from __future__ import annotations

from dataclasses import dataclass
from typing import Dict, Optional, Tuple

import torch
import torch.nn as nn
import torch.nn.functional as F


# ---------------------------------------------------------------------------
# Utility functions
# ---------------------------------------------------------------------------


def compute_residualized_features(
    s: torch.Tensor,
    x: torch.Tensor,
    eps: float = 1e-6,
) -> Tuple[torch.Tenso

GridFormer-InformaNet: Spatio-Informational Modeling for Power Grid Informatization

# GridFormer-InformaNet: Spatio-Informational Modeling for Power Grid Informatization GridFormer-InformaNet is a research-inspired framework designed to explore intelligent informatization in modern power grids. It integrates ideas from graph learning, multimodal data fusion, information-flow modeling, and transformer-based temporal reasoning. The goal is to provide a unified architecture for representing, predicting, and optimizing power system behavior within deeply interconnected cyber-physical infrastructures. This project is based on insights from the paper *"Big Data Platform Architecture and Information Flow Mechanisms in Power Grid Informatization"* authored by **Ai Zhou, Songyao Feng, Zhengyan Huang, and Xuexia Quan**. The repository is intended as a conceptual and experimental implementation rather than an industry-ready system. --- ## 🌐 Motivation Modern power grids operate as **cyber-physical systems** where physical electrical infrastructure and digital information systems are tightly integrated. The emergence of: - large-scale sensor networks, - communication infrastructures, - energy big data platforms, - intelligent control centers, and - real-time coordination mechanisms, brings the need for unified models capable of capturing **both electrical interactions and information-flow interactions**. Traditional power system models often focus on physical topology alone. In contrast, informatized grids require models that simultaneously understand: - physical grid structure, - communication network structure, - heterogeneous state measurements, - decision-making context, - temporal evolution patterns, - and domain-specific operational constraints. GridFormer-InformaNet is designed to address this challenge. --- ## ✨ Key Features ### **1. Multimodal Node Representation** Each node (bus or measurement point) is represented using: - physical state variables, - sensor measurements, - contextual or control features, - topological embeddings. These diverse features are combined into a unified representation of local grid behavior. ### **2. Dual-Graph Message Propagation** The model captures two distinct interactions: - **Physical interactions** via the electrical network, - **Information interactions** via the communication network. Both relationships are essential for informatized grid analysis. ### **3. Temporal Reasoning** GridInformer incorporates sequence modeling through transformer-based temporal encoders. This allows the system to learn: - load evolution, - disturbance propagation, - control response dynamics, - time-correlated behavior of distributed components. ### **4. Predictive Modeling** The architecture provides predictions for: - next-step physical states, - control-relevant intermediate variables, - system evolution patterns. ### **5. Policy Refinement Layer (InformaNet)** Inspired by the paper, the policy layer performs: - local action refinement, - knowledge-based smoothing using graph priors, - optional robustness-aware exploration for decision making. This design bridges representation learning and practical operational decision generation. --- ## 🔍 Conceptual Architecture GridFormer-InformaNet follows a multi-stage processing pipeline: ### **Stage 1 — Multimodal Encoding** Physical, measurement, and contextual data are fused into a high-dimensional latent representation of each node. ### **Stage 2 — Spatio-Informational Propagation** Information is propagated through: - the physical electrical graph, - the communication graph. This dual propagation allows the model to reflect both energy flow and information flow. ### **Stage 3 — Temporal Integration** A temporal encoder processes sequences of graph states, identifying dynamic dependencies. ### **Stage 4 — State and Action Decoding** The latent representation is decoded into: - predicted future states, - candidate control actions. ### **Stage 5 — Policy-Level Enhancement** The policy layer: - refines raw decisions, - applies domain-inspired corrections, - optionally smooths decisions across the network, - produces the final actionable output. --- ## 📚 Data Description (Conceptual) The original article discusses power-grid informatization data sources such as: - real-time monitoring data, - energy load histories, - grid operation logs, - distributed energy behaviors, - big-data-driven analytical information, - communication system metadata, - intelligent control system outputs. This project DOES NOT provide datasets. Users may adapt their own data formats, provided they can construct: - node feature tensors, - physical and communication adjacency matrices, - temporal sequences for model input. --- ## 🚀 Usage Overview The intended usage pattern for this project includes: 1. Preparing input data (states, measurements, actions, adjacency matrices). 2. Feeding data through the multimodal and dual-graph layers. 3. Modeling sequences for temporal behavior. 4. Producing predictions and decision suggestions. 5. Refining decisions with knowledge-guided smoothing. 6. Evaluating performance on forecasting, control, or anomaly detection tasks. This framework is flexible and can be adapted for: - power system forecasting, - cyber-physical anomaly analysis, - smart grid optimization studies, - informatization architecture research, - or educational demonstrations. --- ## 🧩 Extensibility GridFormer-InformaNet is modular, allowing users to extend: - **encoding mechanisms** (add new modalities or positional embeddings), - **graph propagation techniques** (use attention-based GNNs), - **temporal modules** (replace transformers with other sequence models), - **policy logic** (incorporate optimization-based or reinforcement-learning policies), - **constraint-handling strategies** (integration with domain-specific feasibility models). This design enables research exploration across topics in: - power systems, - graph learning, - cyber-physical infrastructures, - autonomous decision systems, - and big data intelligent processing. --- ## 📖 Reference Please credit the original authors when using or modifying this conceptual framework: > Ai Zhou, Songyao Feng, Zhengyan Huang, & Xuexia Quan. > *Big Data Platform Architecture and Information Flow Mechanisms in Power Grid Informatization.* --- ## ⚠️ Disclaimer This repository serves as a **research-oriented conceptual implementation**. It is **not intended for operational use** in real-world power grids without professional validation, testing, and regulatory compliance.
from typing import Optional, Tuple, Dict

import math
import torch
import torch.nn as nn
import torch.nn.functional as F


# ---------------------------------------------------------------------------
# Utility modules
# ---------------------------------------------------------------------------


class MLP(nn.Module):
    """Simple feed-forward network with configurable depth."""

    def __init__(
        self,
        in_dim: int,
        out_dim: int,
        hidden_dim: 

LEFT JOIN時にWHERE句で外部結合の右側テーブルを絞り込んではいけない

# LEFT JOIN と WHERE 句の正しい使い方

## LEFT JOIN の説明

LEFT JOIN(左外部結合)は、左側のテーブル(FROM 句のテーブル)の全レコードを保持しながら、右側のテーブル(JOIN 句のテーブル)と結合する方法。

### LEFT JOIN の動作

- 左側テーブルの全レコードが結果に含まれる
- 右側テーブルに対応するレコードがない場合、右側テーブルの全カラムは**NULL**になる
- この「対応レコードなし →NULL」という挙動が、WHERE 句での絞り込みで問題を引き起こす

## WHERE 句の説明

WHERE 句は、結合後のテーブルに対して行の絞り込みを行う。

### 実行順序

SQL の実行順序は以下の通り:

1. FROM
2. **JOIN**(結合処理)
3. **WHERE**(結合後の絞り込み)
4. GROUP BY
5. HAVING
6. SELECT
7. ORDER BY
8. LIMIT

つまり、WHERE 句は**結合が完了した後**に実行される。

## コードの比較と問題点

###

SAEN-PIGO Employment Prediction

# SAEN-PIGO Employment Prediction This repository provides a reference implementation of the **Stratified Adaptive Employment Network (SAEN)** and the **Policy-Informed Generative Optimization (PIGO)** framework for employment prediction and policy simulation. The code is inspired by the paper *"Deep Learning for College Graduates Employment Prediction: A Computational Approach"* and adapts its main ideas into a practical deep learning project structure. --- ## 1. Overview Modern labor markets are highly dynamic and influenced by: - Individual characteristics (education, age, region, skills) - Employment histories (transitions between employed, unemployed, inactive) - Macroeconomic indicators (unemployment rate, GDP, sector demand) - Policy interventions (subsidies, training programs, incentives) Traditional statistical models often struggle to capture: - Non-linear relationships - Long-term temporal dependencies - Heterogeneity across different groups - Direct effects of policy constraints This project implements a deep learning framework that addresses these issues through: - **SAEN**: A stratified, sequence-based model for employment trajectories - **PIGO**: A policy optimization layer that operates on top of SAEN --- ## 2. Main Components ### 2.1 Stratified Adaptive Employment Network (SAEN) SAEN is designed to model employment dynamics as sequences of states over time: - Each individual belongs (probabilistically) to a **latent stratum** (e.g., age group, education level, region). - Each stratum has its own recurrent unit to capture **group-specific temporal patterns**. - The model incorporates: - **Employment state embeddings** (employed, unemployed, inactive) - **Duration / tenure information** (how long in the current state) - **Individual covariates** (demographics, skills) - **Macroeconomic variables** (e.g., labor market indicators) - **Policy actions** (e.g., training, subsidies) Core ideas: - **Stratum-aware sequence modeling** via group-specific recurrent networks - **Duration and action integration** so the transition probability depends on tenure and interventions - **Macroeconomic attention** to focus on the most relevant historical macro signals - **Residual individual adaptation** to fine-tune group-level behavior for a specific person ### 2.2 Policy-Informed Generative Optimization (PIGO) PIGO is a policy learning and simulation layer that uses SAEN as an environment model. Key ideas: - Treat employment transitions as a **sequential decision problem** - Define a **reward function** that encodes social or organizational objectives, such as: - Higher employment rates - Lower unemployment duration - Fair outcomes across demographic groups - Learn a **stochastic policy** that maps states to policy actions - Integrate: - **Budget or cost constraints** - **Temporal smoothness constraints** (discourage drastic policy changes over time) - **Fairness regularization** across strata The result is a framework that can: 1. Predict employment trajectories under existing conditions 2. Simulate counterfactual outcomes under alternative policies 3. Optimize policies within realistic constraints --- ## 3. Model - `model.py`:Core implementation of SAEN, macroeconomic attention, and PIGO policy network. --- ## 4. Data Representation Although actual datasets are not bundled, the model is designed for generic employment data of the form: - **Sequential records per individual**: - Discrete time steps (e.g., months) - Employment state labels per time step - Tenure in current state - Individual covariates over time (static or slowly varying) - Macroeconomic indicators over time (shared across individuals) - Policy actions applied at each time step The dataset class in this repository is written in a way that you can adapt it to: - Graduate employment datasets - Sector-specific labor datasets - Organizational workforce planning datasets --- ## 5. Training and Evaluation ### 5.1 Training the SAEN model High-level steps: 1. Prepare sequences for each individual. 2. Build train / validation / test splits (preferably chronological). 3. Initialize the SAEN model: - Number of strata - Hidden dimension - Embedding sizes for states, duration, actions - Sizes for individual and macro features 4. Optimize a sequence loss (e.g., negative log-likelihood of next-state prediction). 5. Optionally add: - L1/L2 regularization on parameters - Group sparsity or entropy regularization on strata usage You can integrate early stopping based on validation accuracy, F1 score, or other metrics. ### 5.2 Training the PIGO policy After SAEN is reasonably trained, the policy layer can: - Use SAEN as a **simulator** to roll out trajectories under different policies. - Optimize policy parameters using a policy gradient algorithm: - Estimate returns along sampled trajectories - Include budget constraints via penalties in the loss - Include fairness constraints via penalties on group-level employment gaps - Use a baseline network to reduce gradient variance Evaluation metrics may include: - Overall employment rate at the horizon - Average unemployment duration - Group-level employment parity - Policy cost or budget consumption --- ## 6. Fairness and Ethics Employment prediction and policy simulation can impact real people. This project encourages: - **Fairness-aware training**: - Measure outcomes per stratum (e.g., by region, gender, education level). - Penalize large disparities between groups. - **Transparent use**: - Use the models as decision support, not as the sole decision-maker. - Communicate uncertainty and possible biases in data. - **Ongoing auditing**: - Regularly check performance and fairness metrics. - Update models and policies when data distribution shifts. --- ## 7. Extending the Project Possible directions: - Replace the recurrent backbone with transformer-style sequence encoders. - Add graph-based modules for: - Skill transition graphs - Employer-employee networks - Regional labor mobility graphs - Integrate causal inference techniques to better identify: - True effects of policies - Confounding factors Potential applications: - National or regional labor policy analysis - University graduate employability studies - Organizational workforce planning - Sector-specific labor market analytics --- ## 8. Citation If you use this implementation in a research project or derived work, please cite the original paper on which this implementation is conceptually based, as well as your own project or publication. ---
from __future__ import annotations

from dataclasses import dataclass
from typing import Optional, Tuple, Dict, Any

import math
import torch
from torch import nn, Tensor
from torch.nn import functional as F


# ---------------------------------------------------------------------------
# Utility helpers
# ---------------------------------------------------------------------------


def sequence_mask(lengths: Tensor, max_len: Optional[int] = None) -> Tensor:
    """
    Create