# A Neural-Network-Based Landscape Search Engine:
## 2 Methods and Data
### Ad Hoc Querying  
The querying of results occurs behind the scenes in the web application, which was created with R's web framework, Shiny [26]. On the application's landing page, users are given several input options:  
* Exclusion radius in miles (variable dist, values: 0-300): following [PERSON]'s First Law of Geography, it was expected that nearby locations would be highly similar and that users may want to exclude options within a certain distance in order to retrieve results from farther away. The default is 0, meaning that no locations are excluded due to nearness.
* Number of similar locations to retrieve (variable k, values: 1-10): The default is 5.
* Terrain model (variable resnet50_sim, vgg16_sim, or nasnet_sim, depending on using input from options \"ResNet-50\", \"VGG16\", and \"NasNet\"): The neural network model to use in comparing results.
* Criteria weight for terrain (variable terrain_scale, values of 0-1): Relative weight to use for terrain (default of 0.8). This gives end-users flexibility by allowing them to place more or less emphasis on terrain versus vegetation.
* Criteria weight for NDVI mean vs. NDVI standard deviation (variable veg_mean_scale, values 0-1): Relative weight to use for each of the two NDVI variables (default of 1). This allows users to place more or less emphasis on total vegetation (i.e., mean NDVI similarity) versus the amount of NDVI variability (i.e., NDVI standard deviation).  
Using these input values with the similarities stored in the database, a \"total similarity\" metric is computed on-the-fly after a user selects input options and clicks on the \"Find Similar Landscapes\" button:  
\[\text{total\_sim}=(\text{terrain\_scale}_{u}*\text{model\_sim})+\]  
\[(\text{veg\_scale}_{u}*((\text{veg\_mean\_scale}_{u}*\text{veg\_mean\_sim})+( \text{veg\_sd\_scale}_{u}*\text{veg\_sd\_sim}))\]where  
\[\text{veg\_scale}_{u}=1-\text{terrain\_scale}_{u}\]  
and  
\[\text{veg\_mean\_scale}_{u}=1-\text{veg\_sd\_scale}_{u}\]  
Here, variables noted with the subscript \"\(u\)\" are either taken from or calculated by user input, whereas the others have been computed a priori and are stored on disk. Effectively, total_sim takes the similarity results and scales them based on the user's desired parameters. This metric represents the combined similarity of terrain and vegetation, enabling users to tailor emphasis on one landscape characteristic or the other to suit a specific use case. The relative weight to place on terrain (terrain_scale\({}_{u}\)) is multiplied by the terrain similarity scores as computed by the NN models and the cosine distance between the feature vectors (model_sim). Similarly, the weight to place on vegetation (veg_scale\({}_{u}\))--which is the additive inverse of the weight placed on terrain--is multiplied by the vegetation similarity results. However, since vegetation similarity considers both NDVI mean similarity (veg_mean_sim) and NDVI standard deviation similarity (veg_sd_sim), the weight to place on each of these vegetation metrics is considered as a part of the larger weight placed on vegetation similarity through the inputs veg_mean_scale\({}_{u}\) and veg_sd_scale\({}_{u}\), respectively. The metric total_sim could be thought of as simply a weighted average of similarity results scaled by user input options.  
Other variables are retrieved from user input and queried from the SQLite database using R's ddplyr package [27] (see Figure 2 for a visual representation of the model). Queries are accomplished quickly due to ddplyr's ability to query databases on disk rather than loading an entire dataset into memory; though users may notice a delay of several seconds, the web application currently operates with only 1 GB of memory and a single CPU core.