cosine_similarity

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2023 License: MIT Imports: 1 Imported by: 0

README

Cosine Similarity

This package provides a function for calculating the cosine similarity between two vectors represented as maps of float64 values.

Installation

To install this package, run the following command:

go get github.com/ugurkorkmaz/multiversal

Usage

Import the package in your Go code:

import "github.com/ugurkorkmaz/multiversal/cosine_similarity"

To find the cosine similarity between two vectors, call the Find function with two maps of float64 values:

vectorOne := map[string]float64{
	"a": 1.0,
	"b": 2.0,
	"c": 3.0,
}

vectorSecond := map[string]float64{
	"a": 3.0,
	"b": 2.0,
	"c": 1.0,
}

similarity := cosine_similarity.Find(vectorOne, vectorSecond)

The Find function returns the cosine similarity between the two vectors as a float64 value.

Example

package main

import (
	"fmt"
	"github.com/ugurkorkmaz/multiversal/cosine_similarity"
)

func main() {
	vectorOne := map[string]float64{
		"a": 1.0,
		"b": 2.0,
		"c": 3.0,
	}

	vectorSecond := map[string]float64{
		"a": 3.0,
		"b": 2.0,
		"c": 1.0,
	}

	similarity := cosine_similarity.Find(vectorOne, vectorSecond)

	fmt.Println(similarity)
	// Output: 0.7142857142857143
}

License

This package is licensed under the MIT License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Find

func Find(vectorOne, vectorSecond map[string]float64) float64

The Find function calculates the cosine similarity between two vectors represented as maps of float64 values.

@param vectorOne Map of float64 values representing the first vector.

@param vectorSecond Map of float64 values representing the second vector.

@returns Cosine similarity between two vectors as a float64 value.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL