### Install PyCleora from PyPI Source: https://cleora.ai/docs Use pip to install the pycleora library. This is the recommended installation method. ```bash pip install pycleora ``` -------------------------------- ### Quick Start: Graph Embedding with PyCleora Source: https://cleora.ai/docs A quick start guide to using pycleora for graph embedding. It covers defining edges, building a sparse matrix graph, generating embeddings, and finding similar entities. ```python from pycleora import SparseMatrix, embed, find_most_similar # 1. Define edges (space-separated entity pairs) edges = [ "user_alice product_laptop", "user_alice product_mouse", "user_bob product_keyboard", "user_bob product_monitor", ] # 2. Build the graph graph = SparseMatrix.from_iterator( iter(edges), "complex::reflexive::entity" ) # 3. Generate embeddings (whitening is on by default for best accuracy) embeddings = embed(graph, feature_dim=256) # 4. Query similarity results = find_most_similar(graph, embeddings, "user_alice", top_k=5) for r in results: print(f"{r['entity_id']}: {r['similarity']:.4f}") ``` -------------------------------- ### Install PyCleora from Source Source: https://cleora.ai/docs Install pycleora from its source code, which requires a Rust compiler. This method involves cloning the repository, building with maturin, and then installing the generated wheel file. ```bash pip install maturin==1.2.3 git clone https://github.com/pycleora/pycleora cd pycleora maturin build --release -i python3 pip install target/wheels/pycleora-*.whl ``` -------------------------------- ### Use CLI Tool Source: https://cleora.ai/docs Execute common graph operations directly from the command line. ```bash # Generate embeddings $ pycleora embed --input edges.tsv --dim 1024 --output emb.npz # With algorithm choice $ pycleora embed -i graph.tsv -d 256 -a deepwalk -o emb.npz # Graph info $ pycleora info --input edges.tsv # Find similar entities $ pycleora similar --input edges.tsv --entity alice --top-k 10 # Run benchmarks $ pycleora benchmark --dataset karate_club ``` -------------------------------- ### Sample Graphs Source: https://cleora.ai/docs Perform neighborhood sampling, mini-batching, and link prediction data splitting. ```python from pycleora.sampling import ( sample_neighborhood, sample_subgraph, graphsaint_sample, negative_sampling, train_test_split_edges ) # K-hop neighborhood nbhood = sample_neighborhood(graph, ["alice"], num_hops=2, max_neighbors_per_hop=10) # Mini-batches for large graphs batches = graphsaint_sample(graph, batch_size=512, num_batches=10) # Link prediction data split split = train_test_split_edges(graph, test_ratio=0.2) neg_edges = negative_sampling(graph, num_negatives=1000) ``` -------------------------------- ### Visualize Graph with Labels Source: https://cleora.ai/docs Visualize a graph using the `visualize` function, providing the graph, embeddings, and labels. The output can be saved to a file. ```python visualize(graph, emb, labels=labels, save_path="graph.png") ``` -------------------------------- ### Evaluate Metrics Source: https://cleora.ai/docs Calculate performance scores for node classification, link prediction, and ranking tasks. ```python from pycleora.metrics import ( node_classification_scores, link_prediction_scores, clustering_scores, map_at_k, ndcg_at_k, adjusted_rand_index, silhouette_score ) # Node classification scores = node_classification_scores(graph, emb, labels) # Returns: accuracy, macro_f1, weighted_f1 # Link prediction lp = link_prediction_scores(graph, emb, test_edges) # Returns: auc, mrr, hits@1/3/10/50 # Ranking metrics map_at_k(graph, emb, test_edges, k=10) ndcg_at_k(graph, emb, test_edges, k=10) ``` -------------------------------- ### Import and Export Data Source: https://cleora.ai/docs Save/load embeddings and convert graph formats to NetworkX, PyG, or DGL. ```python from pycleora.io_utils import save_embeddings, load_embeddings, to_networkx # Save/load save_embeddings(graph, emb, "embeddings.npz") emb, ids = load_embeddings("embeddings.npz") # Export to NetworkX, PyG, DGL G = to_networkx(graph, emb) ``` -------------------------------- ### Tune Hyperparameters Source: https://cleora.ai/docs Optimize model parameters using grid or random search. ```python from pycleora.tuning import grid_search, random_search result = grid_search( graph, labels, embed_fn=lambda g, feature_dim=1024, num_iterations=40: embed(g, feature_dim, num_iterations), param_grid={"feature_dim": [256, 512, 1024], "num_iterations": [20, 40, 60]}, ) print(f"Best: {result['best_params']} -> {result['best_score']:.4f}") ``` -------------------------------- ### Generate Synthetic Graphs Source: https://cleora.ai/docs Create standard graph structures using built-in generators. ```python from pycleora.generators import ( erdos_renyi, barabasi_albert, stochastic_block_model, watts_strogatz ) er = erdos_renyi(num_nodes=1000, p=0.01) ba = barabasi_albert(num_nodes=1000, m=3) sbm = stochastic_block_model([100, 100, 100], p_within=0.1, p_between=0.001) ``` -------------------------------- ### Build and Update Graphs Source: https://cleora.ai/docs Construct graphs from iterators and perform dynamic updates or streaming processing. ```python # From edge list graph = SparseMatrix.from_iterator(iter(edges), columns) # Dynamic updates from pycleora import update_graph, remove_edges graph2 = update_graph(edges, new_edges, columns) graph3 = remove_edges(edges, edges_to_remove, columns) # Streaming (batch-by-batch) from pycleora import embed_streaming graph, emb = embed_streaming(batches, columns) ``` -------------------------------- ### RandNE Embedding Algorithm Source: https://cleora.ai/docs Generate embeddings using RandNE, an ultra-fast random projection method. ```python from pycleora.algorithms import embed_randne # RandNE — ultra-fast random projection emb = embed_randne(graph, feature_dim=1024) ``` -------------------------------- ### Manage Heterogeneous Graphs Source: https://cleora.ai/docs Define node and edge types for heterogeneous graphs and perform relation-specific or metapath-based embedding. ```python from pycleora.hetero import HeteroGraph hg = HeteroGraph() hg.add_node_type("user") hg.add_node_type("product") hg.add_edge_type("purchased", "user", "product", [("alice", "laptop")]) # Per-relation embedding graphs, embeddings, combined = hg.embed_per_relation(feature_dim=64) # Metapath embedding g, emb = hg.embed_metapath(["purchased", "sold_at"], feature_dim=64) ``` -------------------------------- ### Standard Embedding with PyCleora Source: https://cleora.ai/docs Generate standard graph embeddings using the `embed` function. Whiten is true by default for optimal accuracy. ```python from pycleora import embed # Standard embedding (whiten=True by default for best accuracy) emb = embed(graph, feature_dim=256) ``` -------------------------------- ### NetMF Embedding Algorithm Source: https://cleora.ai/docs Generate embeddings using NetMF, a matrix factorization method. Requires a negative sampling parameter. ```python from pycleora.algorithms import embed_netmf # NetMF — matrix factorization (requires negative sampling) emb = embed_netmf(graph, feature_dim=1024, negative_samples=1.0) ``` -------------------------------- ### Symmetric Propagation Embedding with PyCleora Source: https://cleora.ai/docs Generate graph embeddings using symmetric propagation. This can be faster but may reduce accuracy compared to the default left propagation. ```python from pycleora import embed # Symmetric propagation emb_sym = embed(graph, feature_dim=256, propagation="symmetric") ``` -------------------------------- ### DeepWalk Embedding Algorithm Source: https://cleora.ai/docs Generate embeddings using the DeepWalk algorithm, which involves random walks and SVD. Requires a negative sampling parameter. ```python from pycleora.algorithms import embed_deepwalk # DeepWalk — random walks + SVD (requires negative sampling) emb = embed_deepwalk(graph, feature_dim=1024, num_walks=20, walk_length=40) ``` -------------------------------- ### Visualize Embeddings Source: https://cleora.ai/docs Tools for dimensionality reduction and visualization. ```python from pycleora.viz import visualize, reduce_dimensions ``` -------------------------------- ### Classify Nodes Source: https://cleora.ai/docs Use built-in MLP classifiers or label propagation for semi-supervised learning. ```python from pycleora.classify import mlp_classify, label_propagation # MLP classifier — dense layers on embedding vectors result = mlp_classify(graph, emb, labels, hidden_dim=64) print(f"Accuracy: {result['accuracy']:.4f}") # Semi-supervised label propagation — no embeddings needed predictions = label_propagation(graph, partial_labels) ``` -------------------------------- ### Node2Vec Embedding Algorithm Source: https://cleora.ai/docs Generate embeddings using Node2Vec, which employs biased random walks. Requires a negative sampling parameter. ```python from pycleora.algorithms import embed_node2vec # Node2Vec — biased walks (requires negative sampling) emb = embed_node2vec(graph, feature_dim=1024, p=0.5, q=2.0) ``` -------------------------------- ### Embed with Node Features Source: https://cleora.ai/docs Inject node-specific features into the embedding process. ```python from pycleora import embed_with_node_features node_features = {"alice": np.array([1.0, 0.5, ...]), ...} emb = embed_with_node_features(graph, node_features, feature_weight=0.7) ``` -------------------------------- ### Embed with Attention Source: https://cleora.ai/docs Generate embeddings using attention-weighted mechanisms. ```python from pycleora import embed_with_attention emb = embed_with_attention(graph, feature_dim=1024, attention_temperature=0.5) ``` -------------------------------- ### Cross-Validate Models Source: https://cleora.ai/docs Perform k-fold cross-validation to assess model stability. ```python from pycleora.metrics import cross_validate cv = cross_validate(graph, emb, labels, k_folds=5) print(f"Accuracy: {cv['mean_accuracy']:.4f} +/- {cv['std_accuracy']:.4f}") print(f"Macro F1: {cv['mean_macro_f1']:.4f} +/- {cv['std_macro_f1']:.4f}") ``` -------------------------------- ### Multi-scale Embedding with PyCleora Source: https://cleora.ai/docs Generate multi-scale embeddings to capture different neighborhood sizes. The resulting feature dimension is feature_dim * number of scales. ```python from pycleora import embed_multiscale # Multi-scale (captures different neighborhood sizes) emb_multi = embed_multiscale(graph, feature_dim=64, scales=[1, 2, 4, 8]) # Result: (n_entities, 64*4) = (n, 256) dimensions ``` -------------------------------- ### Reduce Dimensions with t-SNE Source: https://cleora.ai/docs Use the `reduce_dimensions` function with the 'tsne' method for t-SNE reduction. Ensure embeddings are pre-calculated. ```python emb_2d = reduce_dimensions(emb, method="tsne") ``` -------------------------------- ### Embed with Edge Features Source: https://cleora.ai/docs Incorporate multi-dimensional edge features using concatenation, mean, or edge-only strategies. ```python from pycleora import embed_edge_features # Multi-dimensional features per edge edge_feats = {"alice item_laptop": np.array([1.0, 0.8, ...]), ...} emb = embed_edge_features(graph, edge_feats, feature_dim=64, combine="concat") # combine: "concat" | "mean" | "edge_only" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.