Форум пользователей MySQL
Насколько мне известно в Maria DB появился механизм для работы с графами (OQGRAPH).
А чем, к слову, Вам не нравится идея сохранения пар смежных вершин?
#3 23.07.2011 17:35:27
Re: Как хранить матрицу в БД
Про Maria DB — огромное спасибо.
На счет не нравится — это слишком сильно сказано. Я просто иду другие варианты для хранения и пытаюсь узнать в каких случаях они могут быть более эффективны.
Ведь принимая во внимание, что в для простого графа матрица смежности симметрична и состоит только из <0,1>возможно есть смысл использовать для ее хранения методы для разряженных матриц
#4 23.07.2011 17:40:25
Re: Как хранить матрицу в БД
Хм. Ну, всяческие хитрые форматы типа разреженно-строчного — у них же своя структура, свои массивы, и нет нужды хранить всю матрицу целиком — можно хранить в базе эти самые определяющие матрицу массивы.
А графы, в которых мало ребер я бы хранил скорее в списках смежности
.
Storing Big Matrix in DataBase
What I want to do is for each string, compare it to each other string and store some metric of the comparison. Doing this will essentially yield a 2D matrix of size NxN where N is the number of row in the db.
My initial thought was creating another db where each index corresponds to the string of the index in the first db and each column is the value from comparing the two strings. For example, id 1 column 2 in the second db would be the value outputted from comparing id1 and id2 in the first db.
The format of the second db:
This way of creating the second db would result in 100k rows x 100k columns, which is the issue at hand. What is the best way to handle large data sets like this? Is storing the data in a text file more efficient (say each text file corresponds to one row in the second db.)
Хранение матриц в БД и их выборка, реально?
В БД не очень хорошо разбираюсь, есть в какой ни будь БД поле с типом данных Матрица?
Допустим у меня есть 2 очень похожих матрицы с минимальной разницей
5 5 5
5 5 5
5 5 5
и
5 5 6
5 5 5
5 5 5
Есть какой-то алгоритм что бы быстро найти похожие матрицы, или найти максимально похожую матрицу на эту и т.п.?
- Вопрос задан более трёх лет назад
- 864 просмотра
- Вконтакте
- Вконтакте

DrunkMaster: Да в любой, наверно.
Обработка, разумеется, будет зависеть от выбранной СУБД и способа хранения.
Если РСУБД — заведите в таблице столько столбцов, сколько надо для размещения матрицы. Для обработки или процедуру пишите или переложите на ЯП, какой используете. Варианты разные есть: например, обрабатывать сами данные в R.
Matrix Math in SQL
Relational Databases have tables as data structures, not arrays. This makes it tricky and slow to do matrix operations, but it doesn’t mean it is impossible to do. Joe gives the Celko Slant on how to go about doing Matrix Math in SQL.
I’ve just finished teaching a math class at a local school at night, and we had a section on matrix math and determinants. A matrix is not quite the same thing as an array. Matrices are mathematical structures with particular properties that we cannot take the time to discuss here. You can find that information in a college freshman algebra book. This is similar to subtle differences between “hierarchies and trees”.
Whereas an array is merely a data structure who elements are accessed by a numeric value called an index, a matrix is an array with mathematical operations defined on it. A matrix can be one, two, three or more dimensional structures. The most common mathematical convention has be to use the letters i, j and k for the subscripts.
SQL had neither arrays or matrices because the only data structure is a table. Just as there is no obvious way to model trees and hierarchies in SQL, we need ways to model multi-dimensional arrays in SQL.
Arrays via Named Columns
An array in procedural programming languages has a name, and subscripts by which the array elements are referenced. The array elements are all of the same data type and the subscripts are all sequential integers. Some languages start subscripts at zero, some start at one, and some let the user set the upper and lower bounds of each subscript. Algol 60 even allowed arrays to be declared with dynamic subscripts using expressions in the declarations when program control enters a block; the array is deallocated on exciting the block. Most languages are not that complex. For example, a Pascal array declaration would look like this: