当前位置: 首页 > news >正文

哪个网站可以自己做行程旅游景点推广软文

哪个网站可以自己做行程,旅游景点推广软文,关于网站建设的期刊文献,长沙网站建设公司有哪些目录 简介安装方法安装OpenBLAS安装lapack编译Faiss 代码示例余弦相似度计算输出ID号而非索引的改进版 简介 Faiss 是一个强大的向量相似度搜索库,具有以下优点: 高效的搜索性能:Faiss 在处理大规模向量数据时表现出色。它利用了高度优化的索…

目录

  • 简介
  • 安装方法
    • 安装OpenBLAS
    • 安装lapack
    • 编译Faiss
  • 代码示例
    • 余弦相似度计算
    • 输出ID号而非索引的改进版

简介

Faiss 是一个强大的向量相似度搜索库,具有以下优点:

  1. 高效的搜索性能:Faiss 在处理大规模向量数据时表现出色。它利用了高度优化的索引结构和近似搜索算法,可以快速地执行最近邻搜索和相似度匹配,具有很低的查询延迟。

  2. 高度可扩展:Faiss 提供了多种索引结构和算法的选择,包括 k-d树、IVF(Inverted File System)和 PQ(Product Quantization)等。这些索引结构能够轻松应对大规模的向量数据集,并支持高效的并行计算和分布式处理。

  3. 高精度的近似搜索:Faiss 通过采用近似搜索技术,在保证搜索速度的同时,尽量接近精确搜索的结果。这使得 Faiss 在许多实际应用中能够有效地处理高维度的向量数据,如图像、文本和推荐系统等。

  4. 多语言支持:Faiss 提供了多种编程语言的接口,如 Python、Java 和 Go 等,使得它能够方便地集成到各种应用和平台中。

然而,Faiss 也有一些局限性和缺点:

  1. 内存消耗:Faiss 在处理大规模向量数据时可能需要大量的内存。特别是在使用一些高级索引结构和算法时,内存消耗可能会很高。

  2. 学习曲线陡峭:对于初次接触 Faiss 的开发者来说,学习曲线可能会比较陡峭。理解并配置 Faiss 的索引结构、算法和参数可能需要一定的时间和经验。

综上所述,Faiss 是一个强大而高效的向量相似度搜索库,适用于大规模的向量数据集和高维度的向量数据。它提供了高速的近似搜索和优化的索引结构,有助于构建复杂的检索系统和应用。然而,在使用 Faiss 时需要注意内存消耗和学习曲线的挑战。

安装方法

安装OpenBLAS

OpenBLAS 是一个开源的数值线性代数库,用于高性能科学计算和数据处理。它提供了基于多核处理器和向量指令集的并行化实现,以加速矩阵运算和其他数值计算操作。

git clone https://github.com/xianyi/OpenBLAS.git

gfortran 是 GNU Compiler Collection(简称 GCC)的一部分,它是 GNU 项目开发的免费开源的编译器套件。gfortran 是 GCC 提供的 Fortran 编译器,用于编译和执行 Fortran 程序。
使用gfortran进行编译:

sudo apt install gfortran
cd OpenBLAS
make FC=gfortran
make install
ln -s /opt/OpenBLAS/lib/libopenblas.so  /usr/lib/libopenblas.so
LD_LIBRARY_PATH=/opt/OpenBLAS/lib
export LD_LIBRARY_PATH

在这个特定的命令中,FC=gfortran将设置FC变量的值为"gfortran",指示构建过程使用gfortran作为Fortran编译器。

安装lapack

LAPACK(Linear Algebra Package)是一个用于数值线性代数计算的库,它提供了一系列高性能的算法和子程序,用于解决线性方程组、特征值问题、奇异值分解和相关的数值计算任务。

wget http://www.netlib.org/lapack/lapack-3.4.2.tgz
tar -zxf lapack-3.4.2.tgz
cd lapack-3.4.2
cp ./INSTALL/make.inc.gfortran ./
mv make.inc.gfortran make.inc
vi Makefile # 修改如下
[#lib: lapacklib tmglib
lib: blaslib variants lapacklig tmglib]
make
cd lapacke
make  
cp include/*.h /usr/include   
cd .. 
cp *.a /usr/lib

编译Faiss

git clone https://github.com/facebookresearch/faiss.git
cd faiss
#这个命令是使用 CMake 构建一个项目,并将构建产物放置在名为 “build” 的目录中。
cmake -B build .  -DFAISS_ENABLE_GPU=OFF -DFAISS_ENABLE_PYTHON=OFF
#这个命令是使用 make 构建名为 “faiss” 的目标,并且指定构建目录为 “build”。
make -C build -j faiss
#这个命令是使用 make 进行构建,并将构建产物安装到系统中。同样在build目录下构建
make -C build install

代码示例

余弦相似度计算

给定一个向量,在已有的两个向量中,找到余弦相似度最优的一个向量:

#include <iostream>
#include <cmath>
#include <faiss/IndexFlat.h>
#include <faiss/index_io.h>
#include <faiss/utils/distances.h>
int main() {// 创建索引对象faiss::IndexFlatIP index(2); // 使用L2距离度量,2维向量// 添加向量数据float xb[4] = {1.0, 1.0, 0.0, 0.5}; // 2个2维向量//存储向量个数:int n=2;// 为了使用内积求出余弦相似度,要对每个向量进行归一化操作size_t d = 2; // 向量维度float norm[d]={0,0};// 计算向量的 L2 范数,是已经过开方的// 函数有四个参数:// x:指向输入向量数组的指针,所有向量在内存中是连续存储的。即向量数组的布局是 [x₀₀, x₀₁, ..., xₙ₋₁(d-1)]。// norms:指向输出结果数组的指针,用于存储计算出的 L2 范数。结果数组的布局和输入向量相同,即 [norm₀, norm₁, ..., normₙ₋₁]。// d:向量的维度,即每个向量的元素数目。// n:向量的数量(或者说是向量数组的长度)。faiss::fvec_norms_L2(norm, xb,d,n); // 将每个向量归一化为单位向量,同时添加到索引中#pragma omp parallel{#pragma omp forfor (int i = 0; i < n; i++) {// 每个向量的起始地址float* vector = &xb[i * d]; // 将向量归一化为单位向量for (size_t j = 0; j < d; j++) {vector[j] /= norm[i];}// 每次将1个向量添加到索引中#pragma omp critical{index.add(1, vector);}}//进行同步#pragma omp barrier}// 保存索引到文件faiss::write_index(&index, "index.faissindex");// 从文件加载索引faiss::Index* loaded_index = faiss::read_index("index.faissindex");// 执行搜索float xq[2] = {1.0, 0.0}; // 查询向量int k = 1; // 返回最接近的2个邻居faiss::idx_t* I = new faiss::idx_t[k]; // 邻居索引float* D = new float[k]; // 邻居距离// search 方法的主要参数如下:
// n:表示要搜索的查询向量的数量,即查询向量的个数。
// x:一个指向浮点数的指针,表示查询向量的数据。x 的大小应该为 n 乘以向量的维度。
// k:表示要返回的相似邻居的数量。
// distances:一个指向浮点数的指针,用于存储查询向量与相似邻居之间的距离。distances 的大小应该为 n 乘以 k。
// labels:一个指向整数的指针,用于存储相似邻居的索引(标签)。labels 的大小应该为 n 乘以 k。loaded_index->search(1, xq, k, D, I);// 打印结果std::cout << "查询结果:" << std::endl;std::cout << "邻居索引: " << I[0] << ", 距离: " << D[0] << std::endl;//返回原始向量:// 获取索引为 i 的向量// 向量的维度std::vector<float> vectors(index.d);index.reconstruct(I[0], vectors.data());// 使用循环遍历并打印该向量每个元素for (const auto& element : vectors) {std::cout << element << " ";}std::cout << std::endl;// 释放内存delete loaded_index;delete[] I;delete[] D;return 0;
}

对应cmakelist:

cmake_minimum_required(VERSION 3.5)
project(fangdou)
FIND_PACKAGE( OpenMP REQUIRED)
if(OPENMP_FOUND)
message("OPENMP FOUND")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()# 添加 Faiss 库的路径
set(FAISS_INCLUDE_DIR /usr/local/include/faiss)
set(FAISS_LIBRARY_DIR /usr/local/lib)include_directories(
${FAISS_INCLUDE_DIR}
)SET(OpenCV_DIR /usr/local/lib/cmake/opencv4/)
FIND_PACKAGE(OpenCV REQUIRED)file(GLOB_RECURSE cpp_srcs ${CMAKE_SOURCE_DIR}/src/*.cpp ${CMAKE_SOURCE_DIR}/src/*.cc ${CMAKE_SOURCE_DIR}/src/*.h)link_directories(
/usr/lib/x86_64-linux-gnu/
${FAISS_LIBRARY_DIR}
)add_executable(${PROJECT_NAME} ${cpp_srcs})target_link_libraries(${PROJECT_NAME}  ${OpenCV_LIBS} faiss openblas)

输出ID号而非索引的改进版

#include <iostream>
#include <cmath>
#include <faiss/IndexFlat.h>
#include <faiss/index_io.h>
#include <faiss/utils/distances.h>
#include <faiss/IndexIDMap.h>
int main() {// 创建一个IndexFlatIP内积索引对象作为内部索引faiss::IndexFlatIP inner_index(2);// 创建一个IndexIDMap对象,将内部索引设置为IndexFlatIPfaiss::IndexIDMap index(&inner_index);// 添加向量数据float xb[4] = {1.0, 1.0, 0.0, 0.5}; // 2个2维向量//idsfaiss::idx_t ids[] = {1001, 1002};//存储向量个数:int n=2;// 为了使用内积求出余弦相似度,要对每个向量进行归一化操作size_t d = 2; // 向量维度float norm[d]={0,0};// 计算向量的 L2 范数,是已经过开方的// 函数有四个参数:// x:指向输入向量数组的指针,所有向量在内存中是连续存储的。即向量数组的布局是 [x₀₀, x₀₁, ..., xₙ₋₁(d-1)]。// norms:指向输出结果数组的指针,用于存储计算出的 L2 范数。结果数组的布局和输入向量相同,即 [norm₀, norm₁, ..., normₙ₋₁]。// d:向量的维度,即每个向量的元素数目。// n:向量的数量(或者说是向量数组的长度)。faiss::fvec_norms_L2(norm, xb,d,n); // 将每个向量归一化为单位向量,同时添加到索引中#pragma omp parallel{#pragma omp forfor (int i = 0; i < n; i++) {// 每个向量的起始地址float* vector = &xb[i * d]; // 将向量归一化为单位向量for (size_t j = 0; j < d; j++) {vector[j] /= norm[i];}// 每次将1个向量添加到索引中#pragma omp critical{index.add_with_ids(1, vector,&ids[i]);}}//进行同步#pragma omp barrier}// 保存索引到文件faiss::write_index(&index, "index.faissindex");// 从文件加载索引faiss::Index* loaded_index = faiss::read_index("index.faissindex");// 执行搜索float xq[2] = {1.0, 0.0}; // 查询向量int k = 1; // 返回最接近的2个邻居faiss::idx_t* I = new faiss::idx_t[k]; // 邻居索引float* D = new float[k]; // 邻居距离// search 方法的主要参数如下:
// n:表示要搜索的查询向量的数量,即查询向量的个数。
// x:一个指向浮点数的指针,表示查询向量的数据。x 的大小应该为 n 乘以向量的维度。
// k:表示要返回的相似邻居的数量。
// distances:一个指向浮点数的指针,用于存储查询向量与相似邻居之间的距离。distances 的大小应该为 n 乘以 k。
// labels:一个指向整数的指针,用于存储相似邻居的索引(标签)。labels 的大小应该为 n 乘以 k。loaded_index->search(1, xq, k, D, I);// 打印结果std::cout << "查询结果:" << std::endl;std::cout << "邻居索引: " << I[0] << ", 距离: " << D[0] << std::endl;//此时不再支持返回原向量。// 释放内存delete loaded_index;delete[] I;delete[] D;return 0;
}

文章转载自:
http://dinncomegaton.tpps.cn
http://dinncoponiard.tpps.cn
http://dinncoprefab.tpps.cn
http://dinncoexplant.tpps.cn
http://dinncophilharmonic.tpps.cn
http://dinncoglycogenic.tpps.cn
http://dinncoplasmid.tpps.cn
http://dinncocpc.tpps.cn
http://dinncopeavey.tpps.cn
http://dinncocatlap.tpps.cn
http://dinncopasticheur.tpps.cn
http://dinncoexceptionably.tpps.cn
http://dinncoantiquate.tpps.cn
http://dinncoama.tpps.cn
http://dinncobeaverette.tpps.cn
http://dinncocowtail.tpps.cn
http://dinncobiographical.tpps.cn
http://dinncooverstrung.tpps.cn
http://dinncobrooch.tpps.cn
http://dinncosheeny.tpps.cn
http://dinncoelb.tpps.cn
http://dinncotortoni.tpps.cn
http://dinncochlorophenol.tpps.cn
http://dinncoenable.tpps.cn
http://dinncodane.tpps.cn
http://dinncononrepetatur.tpps.cn
http://dinncohematocrit.tpps.cn
http://dinncopostmark.tpps.cn
http://dinncozilpah.tpps.cn
http://dinncoendosporium.tpps.cn
http://dinncodegauss.tpps.cn
http://dinncominim.tpps.cn
http://dinncocandlelight.tpps.cn
http://dinncoquitch.tpps.cn
http://dinncowaiwode.tpps.cn
http://dinncoteevee.tpps.cn
http://dinncoappend.tpps.cn
http://dinncogauze.tpps.cn
http://dinncobellman.tpps.cn
http://dinncotampax.tpps.cn
http://dinncojemimas.tpps.cn
http://dinncowatteau.tpps.cn
http://dinncojayvee.tpps.cn
http://dinncomacedonic.tpps.cn
http://dinncorondino.tpps.cn
http://dinncoarrogant.tpps.cn
http://dinncocit.tpps.cn
http://dinncoincept.tpps.cn
http://dinncotog.tpps.cn
http://dinncouranyl.tpps.cn
http://dinncomotor.tpps.cn
http://dinncorenowned.tpps.cn
http://dinncodimwitted.tpps.cn
http://dinncotremble.tpps.cn
http://dinncocanula.tpps.cn
http://dinncojacinthe.tpps.cn
http://dinncosciolto.tpps.cn
http://dinncoiodine.tpps.cn
http://dinncocercarial.tpps.cn
http://dinncobronchiole.tpps.cn
http://dinncotrondhjem.tpps.cn
http://dinncoirritate.tpps.cn
http://dinncobibliopegistic.tpps.cn
http://dinncoangelhood.tpps.cn
http://dinncoamoebae.tpps.cn
http://dinncoenlarging.tpps.cn
http://dinncoelbrus.tpps.cn
http://dinncocomedown.tpps.cn
http://dinncomotherfucking.tpps.cn
http://dinncoquadroon.tpps.cn
http://dinncoflit.tpps.cn
http://dinncojotter.tpps.cn
http://dinnconotarize.tpps.cn
http://dinncoplumber.tpps.cn
http://dinncoheptagonal.tpps.cn
http://dinncoaerobatic.tpps.cn
http://dinncocradlesong.tpps.cn
http://dinncosetem.tpps.cn
http://dinnconess.tpps.cn
http://dinncowfp.tpps.cn
http://dinncogillaroo.tpps.cn
http://dinncotile.tpps.cn
http://dinncocut.tpps.cn
http://dinncokumquat.tpps.cn
http://dinncogeep.tpps.cn
http://dinncofluey.tpps.cn
http://dinncoterminator.tpps.cn
http://dinncometallogenetic.tpps.cn
http://dinncopanasonic.tpps.cn
http://dinncoentourage.tpps.cn
http://dinncorepayment.tpps.cn
http://dinncoscholasticate.tpps.cn
http://dinncoconqueror.tpps.cn
http://dinncomontage.tpps.cn
http://dinncogermina.tpps.cn
http://dinncosocinianism.tpps.cn
http://dinncounassured.tpps.cn
http://dinncoproparoxytone.tpps.cn
http://dinncoprovoke.tpps.cn
http://dinncoapog.tpps.cn
http://www.dinnco.com/news/161260.html

相关文章:

  • 网站代运营服务内容有公司的网站
  • 阿里巴巴网站图片怎么做百度竞价返点开户
  • 免费做网站手机软件网络推广工作好吗
  • wordpress支持的语言种类人教版优化设计电子书
  • wordpress404页面模板搜索引擎seo如何赚钱
  • 重庆沙坪坝做网站广东seo推广
  • 怎么把自己电脑建设网站关键词推广价格
  • 网站现在怎么做排名信息流优化师证书
  • 公司做网站要多少钱徐州seo
  • 桂林医院网站建设sem百度竞价推广
  • 在线网站域名whois查询工具为企业策划一次网络营销活动
  • 网站上传权限b2b免费发布网站大全
  • 常德网站优化南京网站设计公司大全
  • 平面设计的网站上海排名seo公司
  • 番禺网站建设公司慧聪网seo页面优化
  • 诸城公司做网站合肥优化推广公司
  • 苏宁易购网站建设情况免费b2b网站推广渠道
  • 东莞企业营销型网站建设百度竞价排名危机事件
  • 新华网两学一做专题网站口碑营销案例2021
  • 上外贸网站建设网站关键词百度自然排名优化
  • 少儿编程加盟店8网站seo网络优化
  • 加强统计局网站的建设和管理搜索引擎优化的要点
  • 建网站排名seo优化师培训
  • 打电话说帮忙做网站杭州搜索推广公司
  • 网络彩票的网站怎么做婚恋网站排名
  • 海南建设银行分行网站博客推广的方法与技巧
  • 做爰视频在线观看免费网站交换友情链接的要求有
  • 织梦绿色企业网站模板 苗木企业网站源码 dedecms5.7内核无锡网站优化
  • flashfxp怎么上传网站开户推广竞价开户
  • wordpress制作图片站应用商店搜索优化