### Generate Random Cuisines for Statistical Analysis (Java) Source: https://context7.com/pepton21/flavor-network/llms.txt Provides methods for generating baseline random cuisines to compare against real cuisines, enabling statistical analysis of ingredient pairing patterns. It supports generation from existing recipes or using a Poisson distribution, and calculates Delta Ns to quantify differences from random. ```java // Generate random cuisine from existing recipes (recommended method) // Randomly samples 10,000 recipes from all cuisines Cousine randomCousine = Cousine_Data.generateRandomCousineFromExistingRecepies(10000); double randomNs = randomCousine.getNs(); System.out.println("Random baseline Ns: " + randomNs); // ~8.5 // Calculate Delta Ns (difference from random) // Positive = more compound sharing than random // Negative = less compound sharing than random Cousine northAmerican = cousines.get("NorthAmerican"); Cousine eastAsian = cousines.get("EastAsian"); double deltaNs_NA = northAmerican.getNs() - randomNs; // Positive (~3.0) double deltaNs_EA = eastAsian.getNs() - randomNs; // Negative (~-2.4) System.out.println("North American Delta Ns: " + deltaNs_NA); // Western: positive System.out.println("East Asian Delta Ns: " + deltaNs_EA); // Eastern: negative // Alternative: Poisson-based random generation (less effective) // Uses Poisson distribution for recipe sizes, uniform for ingredients double avgIngredientsPerRecipe = Cousine_Data.getAvgNumIngredientsPerRecipe(); Cousine poissonRandom = Cousine_Data.generateRandomCousine(10000, avgIngredientsPerRecipe); ``` -------------------------------- ### Write Recipe Size Distributions (Java) Source: https://context7.com/pepton21/flavor-network/llms.txt Exports recipe size distributions for all cuisines to a CSV file named 'Recipe Size Distributions.csv'. The format includes CuisineName and fractions of recipes with 1, 2, or more ingredients. ```java // Write recipe size distributions for all cuisines // Output: Recipe Size Distributions.csv Cousine_Data.writeRecipeSizeDist(); // Format: CuisineName,fraction_1_ingredient,fraction_2_ingredients,... ``` -------------------------------- ### Write Ingredient Frequencies per Cuisine (Java) Source: https://context7.com/pepton21/flavor-network/llms.txt Exports ingredient frequencies per cuisine to a text file named 'Ingredient frequency per cousine.txt'. The format lists CuisineName followed by a list of ingredient frequencies. ```java // Write ingredient frequencies per cuisine // Output: Ingredient frequency per cousine.txt Cousine_Data.writeIngredientFreqPerCousine(); // Format: CuisineName = [freq1,freq2,freq3,...]; ``` -------------------------------- ### Java Recipe Class: Ingredient Collection and Analysis Source: https://context7.com/pepton21/flavor-network/llms.txt The Recipe class represents a single recipe as a collection of ingredients. It provides methods to add/remove ingredients, count them, calculate the Ns (mean number of shared compounds) measure, and check for the presence of specific ingredients, pairs, or triplets. It also supports cloning for comparative analysis. ```java Recipe butterCookies = new Recipe(); butterCookies.addIngredient(butter); butterCookies.addIngredient(egg); butterCookies.addIngredient(vanilla); butterCookies.addIngredient(wheat); int ingredientCount = butterCookies.count(); // Returns 4 double nsValue = butterCookies.getNs(); // Mean shared compounds across all pairs boolean hasEgg = butterCookies.containsIngredient("egg"); // true boolean hasPair = butterCookies.containsPair("butter", "vanilla"); // true boolean hasTriplet = butterCookies.containsTriplet("butter", "egg", "vanilla"); // true Recipe modified = butterCookies.clone(); modified.removeIngredient("vanilla"); double newNs = modified.getNs(); // Recalculate Ns without vanilla System.out.println("Ns change after removing vanilla: " + (nsValue - newNs)); ``` -------------------------------- ### Print Ns Change After Removing Ingredients (Java) Source: https://context7.com/pepton21/flavor-network/llms.txt Prints the change in Ns values after removing ingredients to the console, formatted for MATLAB. This is used for generating bubble charts and requires ingredient contributions and a specified cuisine. ```java // Print Ns change after removing ingredients (for bubble charts) ArrayList contributions = Cousine_Data.getIngredientContributions(cuisine); Cousine_Data.printNsChangeAfterRemovingIngredients(35, contributions, cuisine); // Output format (to console for MATLAB copy): // removed = [0,1,2,3,...,35]; // Ns = [11.5,11.2,10.9,...]; ``` -------------------------------- ### Run Flavor Network Analysis - Java Source: https://context7.com/pepton21/flavor-network/llms.txt The main orchestrating class for the flavor network analysis. It loads flavor network and recipe data, performs statistical analyses, and generates output files for visualization. Key functionalities include calculating average ingredients per recipe, generating distribution plots, and analyzing specific cuisines. ```java public class Cousine_Data { static HashMap ingredients; static HashMap cousines; public static void main(String[] args) { // Load the flavor network and recipes from CSV files readData(); // Basic statistics System.out.println("Number of ingredients in network: " + ingredients.size()); System.out.println("Average number of ingredients per recipe: " + getAvgNumIngredientsPerRecipe()); // Generate outputs for recipe size distributions writeRecipeSizeDist(); writeIngredientFreqPerCousine(); // Generate random baseline cuisine for comparison (10,000 recipes) Cousine randomCousine = generateRandomCousineFromExistingRecepies(10000); System.out.println("Ns measure of random cuisine: " + randomCousine.getNs()); // Analyze specific cuisines Cousine northAmerican = cousines.get("NorthAmerican"); Cousine eastAsian = cousines.get("EastAsian"); // Generate regression data for pair analysis writePRForCousine(northAmerican); writePRForCousine(eastAsian); // Print authenticity tables (top 6 ingredients, pairs, triplets) printCousineAuthenticity(northAmerican, 6); printCousineAuthenticity(eastAsian, 6); // Analyze ingredient contributions to Ns measure ArrayList contributions = getIngredientContributions(northAmerican); printNsChangeAfterRemovingIngredients(35, contributions, northAmerican); } } ``` -------------------------------- ### Write Pair Regression Data for Cuisine (Java) Source: https://context7.com/pepton21/flavor-network/llms.txt Exports pair regression data for a specific cuisine to a CSV file (e.g., 'NorthAmericanPr.csv'). The output includes shared compound counts and the fraction of pairs in recipes, formatted for regression analysis. ```java // Write pair regression data for specific cuisine // Output: NorthAmericanPr.csv, EastAsianPr.csv Cousine_Data.writePRForCousine(cousines.get("NorthAmerican")); Cousine_Data.writePRForCousine(cousines.get("EastAsian")); // Format: // Line 1: shared_compound_counts (0,1,2,3,...) // Line 2: fraction_of_pairs_in_recipes (0.1,0.15,0.22,...) ``` -------------------------------- ### Analyze Ingredient Authenticity and Prevalence (Java) Source: https://context7.com/pepton21/flavor-network/llms.txt Calculates and sorts ingredients, pairs, and triplets by their relative prevalence (authenticity) within a specific cuisine. It requires cuisine and ingredient data, and outputs lists of authentic ingredients, pairs, and triplets, along with ingredient contribution analysis. ```java // Calculate relative prevalence (authenticity) for single ingredients // Higher relative prevalence = more authentic to that cuisine double relativePrev = Cousine_Data.getIngredientRelativePrevailance(soyIngredient, eastAsianCuisine); // Get sorted list of ingredients by authenticity ArrayList authenticIngredients = Cousine_Data.getIngredientPrevailances(eastAsianCuisine); for (int i = 0; i < 6; i++) { IngredientPrevailance ip = authenticIngredients.get(i); System.out.println(ip.ingredient.name + ": " + ip.prevailance); } // Output for East Asian: // soy sauce: 0.5404 // garlic: 0.5168 // scallion: 0.4726 // cayenne: 0.4004 // sesame oil: 0.3730 // rice: 0.3376 // Analyze authentic pairs (requires top 50 ingredients as input) ArrayList top50 = new ArrayList<>(); for (int i = 0; i < 50 && i < authenticIngredients.size(); i++) { top50.add(authenticIngredients.get(i).ingredient.name); } ArrayList authenticPairs = Cousine_Data.getPairPrevailances(eastAsianCuisine, top50); // Top pair for East Asian: garlic + scallion (0.3537) // Analyze authentic triplets ArrayList authenticTriplets = Cousine_Data.getTripletPrevailances(eastAsianCuisine, top50); // Top triplet for East Asian: garlic + scallion + cayenne (0.2439) // Ingredient contribution analysis (how much each ingredient affects Ns) ArrayList contributions = Cousine_Data.getIngredientContributions(northAmerican); // Sorted by contribution: highest contributors favor compound sharing // For North American: butter, egg, vanilla have high positive contributions // For East Asian: removing low-contribution ingredients increases Ns ``` -------------------------------- ### Flavor Network and Recipe Data Input Formats (CSV) Source: https://context7.com/pepton21/flavor-network/llms.txt Specifies the required CSV file formats for project input: a flavor network defining compound relationships between ingredients and a recipe dataset listing cuisines and their ingredients. ```csv # Network without labels.csv - Flavor compound network # Format: ingredient1,ingredient2,shared_compound_count black_sesame_seed,rose_wine,3 fennel,wild_berry,5 comte_cheese,grape,57 black_pepper,gruyere_cheese,12 beef_broth,wine,1 # Recipes.csv - Recipe dataset by cuisine # Format: CuisineName,ingredient1,ingredient2,ingredient3,... African,chicken,cinnamon,soy_sauce,onion,ginger African,butter,pepper,onion,cardamom,cayenne,ginger,cottage_cheese,garlic,brassica NorthAmerican,butter,egg,wheat,vanilla,milk EastAsian,soy_sauce,garlic,scallion,sesame_oil,rice WesternEuropean,butter,cream,wheat,egg,wine ``` -------------------------------- ### Java Cousine Class: Regional Cuisine Analysis Source: https://context7.com/pepton21/flavor-network/llms.txt The Cousine class represents a regional cuisine, containing multiple recipes. It offers comprehensive analysis methods including Ns calculation, ingredient prevalence across recipes, pair/triplet analysis, and contribution metrics. It also supports cloning for comparative analysis. ```java Cousine northAmerican = new Cousine("NorthAmerican"); northAmerican.addRecipe(butterCookies); northAmerican.addRecipe(applePie); northAmerican.addRecipe(chickenSoup); int recipeCount = northAmerican.count(); // Number of recipes int maxRecipeSize = northAmerican.largestRecipeLength(); // Largest recipe ingredient count int recipesWithEgg = northAmerican.numRecipesContainingIngredient("egg"); double cuisineNs = northAmerican.getNs(); System.out.println("North American Ns: " + cuisineNs); // Higher = more compound sharing double butterPrevalence = northAmerican.getIngredientPrevalence("butter"); // e.g., 0.4115 double pairPrevalence = northAmerican.getPairPrevalence("egg", "wheat"); // e.g., 0.2758 double tripletPrevalence = northAmerican.getTripletPrevalence("butter", "egg", "wheat"); // e.g., 0.1917 double butterContribution = northAmerican.calculateIngredientContribution("butter"); // Positive = ingredient increases compound sharing, negative = decreases HashMap allPairs = northAmerican.getAllPairWeights(); HashMap recipePairs = northAmerican.getRecipePairWeights(); Cousine clonedCuisine = northAmerican.clone(); clonedCuisine.removeIngredient("butter"); System.out.println("Ns after removing butter: " + clonedCuisine.getNs()); ```